<分区>
我假装编写一个可以充当变体类型的类。 一切正常,但是当我尝试分配一个字符串时,调用的方法是使用 bool 作为参数的方法:
class value_t {
public:
value_t operator=(const int& integer) {
std::cout<<"integer"<<std::endl;
return *this;
};
value_t operator=(const std::string& str) {
std::cout<<"string"<<std::endl;
return *this;
};
value_t operator=(const bool& boolean) {
std::cout<<"boolean"<<std::endl;
return *this;
};
};
value_t val;
val = "Hola mundo";
输出是:
boolean
为什么不调用字符串赋值运算符方法?
谢谢