Error C2662

錯誤提示:

錯誤 C2662 “int credit_card::calc_free_days(boost::gregorian::date)”: 不能將“this”指針從“const credit_card”轉換爲“credit_card &”chapter2 d:\project\boost\chapter2\eg_date_time\eg1.cpp24

該錯誤同時還會提示消息:對象含有與成員函數不兼容的類型限定符。



錯誤消息

“function”: 不能將“this”指針從“type1”轉換爲“type2”

編譯器不能將 this 指針從 type1 轉換爲 type2

此錯誤可能是由對 const 對象調用非 const 成員函數引起的。可能的解決方案:

  • 從對象聲明中移除 const

  • 將 const 添加到成員函數中。

下面的示例生成 C2662:

// C2662.cpp
class C {
public:
   void func1();
   void func2() const{}
} const c;

int main() {
   c.func1();   // C2662
   c.func2();   // OK
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章