爲什麼編譯器會在指定的行處發生抱怨?爲什麼我會在這段代碼中得到一個錯誤的錯誤?
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) –