关于运算符重载
同桌老王 2004-10-25 04:42:10 编译环境WinXP + VC6
class CInt
{
public:
void setValue(unsigned int v);
unsigned int getValue() const;
CInt();
CInt(unsigned int v);
virtual ~CInt();
void operator=(unsigned int v);
CInt& operator=(CInt&v);
CInt& operator*(const CInt& v1,const CInt& v2);
CInt& operator+(CInt&v1,CInt&v2);
CInt& operator-(CInt&v1,CInt&v2);
CInt& operator*(CInt&v1, unsigned int v2);
CInt& operator+(CInt&v1, unsigned int v2);
CInt& operator-(CInt&v1, unsigned int v2);
CInt& operator*=(CInt&v1);
CInt& operator+=(CInt&v1);
CInt& operator-=(CInt&v1);
private:
unsigned int m_value; // indicate the value
};
错误:
Compiling...
Int.cpp
\int.h(22) : error C2804: binary 'operator *' has too many parameters
\int.h(23) : error C2804: binary 'operator +' has too many parameters
\int.h(24) : error C2804: binary 'operator -' has too many parameters
\int.h(25) : error C2804: binary 'operator *' has too many parameters
\int.h(26) : error C2804: binary 'operator +' has too many parameters
\int.h(27) : error C2804: binary 'operator -' has too many parameters
Error executing cl.exe.