【发布时间】:2013-03-16 00:39:52
【问题描述】:
我有一个简单的类,旨在将整数转换为字节数组。
class mc_int {
private:
int val; //actual int
public:
int value(); //Returns value
int value(int); //Changes and returns value
mc_int(); //Default constructor
mc_int(int);//Create from int
void asBytes(char*); //generate byte array
mc_int& operator=(int);
mc_int& operator=(const mc_int&);
bool endianity; //true for little
};
为了转换和更简单的使用,我决定添加operator= 方法。但我认为我对mc_int& operator=(const mc_int&); 的实现不正确。
mc_int& mc_int::operator=(const mc_int& other) {
val = other.value();
// |-------->Error: No instance of overloaded function matches the argument list and object (object has type quelifiers that prevent the match)
}
这可能是什么?我尝试使用other->value(),但这也是错误的。
【问题讨论】:
标签: c++ oop operator-overloading