您的位置:首页 > 其它

Error C2662

2016-04-12 20:32 267 查看
错误提示:

错误 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
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: