[转] 'function' : number overloads have no legal conversions for 'this' pointer

前几天就遇到了这个错误,一直没有解决。今天又拿起了前几天写的代码,在网上搜了一下,终于搞定这个问题。
下面是从一个网站上转过来的解决方法。我是直接在我的引起错误的函数名后面加了const限定就可以了。
'function' : number overloads have no legal conversions for 'this' pointer
2008-09-24 16:21

The compiler could not convert the this pointer to any of the overloaded versions of the member function.

This error may be caused by invoking a non-const member function on a const
object.
 To correct the problem, remove the const from the object declaration
or add const to one of the member function overloads.

The following is an example of this error:

class C {
public:
   void foo() volatile;
   void foo(); // adding const here would fix problem
};

const C *pcc;

void main()
{
   pcc->foo();      // error
}

 

ps:
if you declare the const object, the member function to be called should be const.
if you declare the non const object, it would call the normal member function, or call the const member function(if exit, and   no normal member function declaration);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值