这是我写的重载运算符的小程序但是有错误,希望大家帮忙看一下。谢谢!
#include<iostream>
using namespace std;
class Point {
private:int m;
public: Point(int a){m=a;}
Point operator ++(int){ Point point=*this;
++( *this);
return point;}
Point operator --(int){Point point=*this;
--(*this);
return point;}
};
void main(){
int m;
cout<<"please enter your numbaer:"<<endl;
cin>>m;
Point point(m);
cout<<"point++"<<point++<<endl<<"point--:"<<point--<<endl;
}
错误调试:
--------------------Configuration: 11 - Win32 Debug--------------------
Compiling...
11.cpp
D:\学习文件\CL\8-10\11\11.cpp(7) : error C2675: unary '++' : 'class Point' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\学习文件\CL\8-10\11\11.cpp(10) : error C2675: unary '--' : 'class Point' does not define this operator or a conversion to a type acceptable to the predefined operator
D:\学习文件\CL\8-10\11\11.cpp(18) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class Point' (or there is no acceptable conversion)
执行 cl.exe 时出错.
11.obj - 1 error(s), 0 warning(s)