#include <iostream>
using namespace std;
class Foo{
string _s;
public:
Foo(string ss){
_s = ss;
}
Foo& operator=(bool b){
cout << "bool" << endl;
return *this;
}
Foo& operator=(const string& ss){
cout << "another one" << endl;
return *this;
}
};
int main(){
Foo f("bar");
f = "this";
return 0;
}
我重载了=
运算符。我期望f = "this";
语句调用operator=(const string& ss)
重载。但事实并非如此。它称为operator=(bool b)
重载。为什么?