标题:[求助]下面调用函数有什么不同吗?
只看楼主
z_jzhao
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-9-29
 问题点数:0 回复次数:1 
[求助]下面调用函数有什么不同吗?
#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();

};
搜索更多相关主题的帖子: 函数 
2007-09-29 15:01
刘军
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-9-24
得分:0 
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();

}
运行上述代码,你就知道有什么区别了
2007-10-01 03:18



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-174021-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 2.046357 second(s), 9 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved