天天看点

find_if 仿函数错误:cannot convert 'this' pointer from 'const CActTaskData' to 'CActTaskData &'

今天编写find_if的仿函数时编译报错,cannot convert 'this' pointer from 'const cacttaskdata' to 'cacttaskdata &'。

这个编译错误的主要原因是:程序中定义了一个const 类指针,然后用该指针调用了一个非const的函数。由于const对象在调用成员函数的时候,会将this指针强行转换为const this,所以它将无法找到相应的const getint

函数,并且编译器也无法将一个const的对象转化为一个普通对象来调用这个普通的getint函数。

     解决方法有:1、将const 限制去除。2、添加const 版本的getint函数

继续阅读