为什么编译器会在指定的行处发生抱怨?为什么我会在这段代码中得到一个错误的错误?
class C
{
std::string s;
public:
C() { s = "<not set>";}
~C() {}
void Set(const std::string ss) { s=ss; }
const std::string Get() { return s; }
C &operator=(const C &c) { Set(c.Get()); return *this; }
//error: passing ‘const C’ as ‘this’ argument of ‘const string C::Get()’
// discards qualifiers [-fpermissive]
//C &operator=(C &c) { Set(c.Get()); return *this; } <-- works fine
};
'-fpermissive'不是错误,它是一个标志来控制生成的错误。请参阅[什么是fpermissive标志吗?](http://stackoverflow.com/questions/8843818/what-does-the-fpermissive-flag-do) –