构造函数的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 是指针