问个SB基础问题!

qq604622530 2009-04-26 12:55:07
#include <iostream>
using namespace std;
class A
{
public:
inline void func(int,int);
inline void print();
private:
int i,j;
};
int main()
{
return 0;
}
void A::func(int x,int y) //这句很不懂
{
i=x;
j=y;
}
void A::print()
{
cout<<"两数相乘结果为:"<<i*j<<endl;
}


----------
void A::func(int x,int y) 到底是什么意思?是用A这个类去访问成员吗 还是什么?
...全文
94 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
baiwei156 2009-04-26
  • 打赏
  • 举报
回复

void A::func(int x,int y) //这句很不懂
{
i=x;
j=y;
}


类A里的inline void func(int,int);只是声明说,这个类里由这个函数。

上面的是对这个函数的实现。
mengde007 2009-04-26
  • 打赏
  • 举报
回复
这儿不正是对于类A的函数fun(int,int)的定义吗;
aaaa3105563 2009-04-26
  • 打赏
  • 举报
回复
呵呵·· 定义咧
lingyin55 2009-04-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 qq604622530 的帖子:]
#include <iostream>
using namespace std;
class A
{
public:
inline void func(int,int);
inline void print();
private:
int i,j;
};
int main()
{
return 0;
}
void A::func(int x,int y) //这句很不懂
{
i=x;
j=y;
}
void A::print()
{
cout < <"两数相乘结果为:" < <i*j < <endl;
}


----------
void A::func(int x,int y) 到底是什么意思?是用A这个类去访问成…
[/Quote]

void A::func(int x,int y) //这句很不懂
其实这句就是对类成员函数的实现,因为这个函数不是在类里面实现的,所以前面必须加上类名A和
域限定符::,表明这是类A的成员函数,而函数的返回类型(这里为void)则被写到最前面。
Rysle 2009-04-26
  • 打赏
  • 举报
回复
类成员函数的类外实现
qqwx_1986 2009-04-26
  • 打赏
  • 举报
回复
#include <iostream> 
using namespace std;
class A
{
public:
inline void func(int,int); //这里是它的声明点
inline void print();
private:
int i,j;
};
int main()
{
return 0;
}
void A::func(int x,int y) //类的成员函数在类外面的定义而已
{
i=x;
j=y;
}
void A::print()
{
cout <<"两数相乘结果为:" <<i*j <<endl;
}
deltamaster 2009-04-26
  • 打赏
  • 举报
回复
类的描述中写了这个函数的函数头,通过这种写法可以把函数实现写在类外面。
void A::print()也是一样的意思。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧