读书人

形参里的变量名跟类的成员变量一样就不

发布时间: 2012-09-03 09:48:39 作者: rapoo

形参里的变量名和类的成员变量一样就不能正常输出了。
#include <iostream.h>
//
class point
{
public:
int x;
int y;
point()
{
x=0;
y=0;
}
point(int a,int b)
{
x=a;
y=b;
}
void output()
{
cout<<x<<endl<<y<<endl;
}
void input(int x,int y)//这里的形参x、y是不是和类里的int x,int y混淆了。换个其他变量名就没问题。
{
x=x;
y=y;
}
};

void main()
{
point pt(5,5);
pt.input(11,11);
pt.output();
}//非常不懂换名字就能正常,为什么和类的成员变量同名就不正常了。有人能把原理说明白吗,我脑子卡住了,理解不了。

[解决办法]
1L正解
LZ真逗

读书人网 >C++

热点推荐