首页 新闻 赞助 找找看

c++函数名?

0
悬赏园豆:5 [已解决问题] 解决于 2016-09-04 13:49

不是都说函数名功能类似指针,是一个入口地址嘛,我想问问对于类函数名输出错误是为啥?

#include <iostream>

using namespace std;
class A{
public:
int a1;
char b1;
void printthevalue()
{
cout<<a1<<&a1<<endl;
}
void printthevalue1(int s)
{
a1=s;
cout<<a1<<&a1<<endl;
}

};
void sample()
{
cout<<"this just a fun"<<endl;}
int main()
{
A one;

one.a1=3;
one.b1=8;
one.printthevalue();
one.printthevalue1(90);
sample();

cout<<*sample<<endl;
cout<<&sample;
cout<<sample<<endl;
cout<<one.printthevalue<<endl;


return 0;
}

还有,sample输出的地址为啥是1呢?

34没错,35就有错,都是函数名,为啥呢

邗影的主页 邗影 | 初学一级 | 园豆:73
提问于:2016-06-06 23:19
< >
分享
最佳答案
0

void printthevalue() 相当于 void printthevalue(void) 需要理解C++的编译规则

在编译的时候,编译器编译函数,生成一个类似"_printthevalue_void"的名称放在库中,你不带()就相当一个变量,而不是函数

再举个例子 void printthevalue(int, int)编译后,就是 _printthevalue_int_int

收获园豆:5
Yip21st | 菜鸟二级 |园豆:222 | 2016-06-09 01:15
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册