重载异或运算符
class Test
{
private:
unsigned crc;
public:
Test();
Test operator ^(unsigned &);
Test(unsigned c);
}
Test::Test():crc(0){}
Test::Test(unsigned c)
{
crc=c;
}
Test Test::operator ^(unsigned &c)
{
return Test(this->crc^c);
}
int main()
{
Test test;
test=test^2; //编译能不过
return 0;
}
[解决办法]
//首先,没有加 ‘;’class Test{};//没有加;test=test^2; //这里报错 no operator defined which takes a right-hand operand of type 'const int'//其次,改成如下 unsigned int t=2;test=test^t; //编译能不过