C++运算符重载,一道简单的习题,出现错误,求解答。
#include <iostream>
using std::cout;
using std::endl;
class Point {
public:
Point(int a=1,int b=1)
{
_x=a;
_y=b;
}
~Point();
Point& operator ++ ()
{
_x++;
_y++;
return Point(_x,_y);
}
Point operator ++(int)
{
_x++;
_y++;
return Point(_x,_y);
}
Point& operator --()
{
_x--;
_y--;
return Point(_x,_y);
}
Point operator --(int)
{
_x--;
_y--;
return Point(_x,_y);
}
void show () {
cout<<_x<<_y<<endl;
}
private:
int _x;
int _y;
};
int main () {
Point a;
a++;
a.show;
++a;
a.show;
--a;
a.show;
a--;
a.show;
return 0;
}
用类型为‘Point’的右值初始化类型为‘Point&’的非常量引用无效
statement cannot resolve address of overloaded function