注册 登录
编程论坛 新人交流区

[求助]下面调用函数有什么不同吗?

z_jzhao 发布于 2007-09-29 15:01, 352 次点击
#include<iostream.h>
class point
{
public:
int x;
int y;
void init()
{
x=0;
y=0;
}
void output()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}
};
void main()
{
point pt;
pt.init(); //若用pt.init;语句则输出为负长整型数,pt.init()和pt.init用什么不同,为什么会这样?

pt.output();

};
1 回复
#2
刘军2007-10-01 03:18
pt.init() 能调用类的方法
pt.init;会有一个警告 为什么不是一个错误
#include<iostream.h>
#include<stdio.h>
class point
{
public:
int x;
int y;
void init()
{
x=0;
y=0;
}
void output()
{
cout<<"x="<<x<<endl<<"y="<<y<<endl;
}
};
void main()
{
point pt;
pt.init; //若用pt.init;语句则输出为负长整型数,pt.init()和pt.init用什么不同,为什么会这样?
printf("%d\n",&pt.x);
printf("%d\n",&pt.y);
printf("%d\n",pt.init);
printf("%d\n",pt.output);
pt.output();

}
运行上述代码,你就知道有什么区别了
1