首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

构造函数的this,该怎么处理

2012-04-13 
构造函数的thisclass Point{private:int xint ypublic:Point (int x,int y){this.xxthis.yy}Point (

构造函数的this
class Point
{
private:
int x;
int y;
public:
Point (int x,int y)
{
this.x=x;
this.y=y;
}
Point ()
{
x=5;
y=10;
}
~Point ()
{
}
void output()
{
cout<<x<<endl<<y<<endl;
}
};
重载的带参构造函数中,为什么不能用this?
error C2228: left of '.x' must have class/struct/union type
error C2228: left of '.y' must have class/struct/union type
而使用a,b做参数,不使用this就不会出错,大大求解一下,谢谢

[解决办法]

C/C++ code
Point (int x,int y){this->x=x;this->y=y;}
[解决办法]
this->x=x;
this->y=y;

this 是个指针,要像上面那样吧
[解决办法]
楼上的说的很清楚了!结贴吧LZ
[解决办法]
this 是指针

热点排行