find_if 仿函数错误:cannot convert 'this' pointer from 'const CActTaskData' to 'CActTaskData &'
2013-03-12 18:25
411 查看
今天编写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函数
struct act_task_finder { public: act_task_finder(const OBJID objId) : m_ObjId(objId) {} bool operator()(const CActTaskData* pActTaskData) { return pActTaskData->GetInt(USER_TASK_DATA_TASK_ID) == m_ObjId;// 此行报错 } private: OBJID m_ObjId; };
这个编译错误的主要原因是:程序中定义了一个const 类指针,然后用该指针调用了一个非const的函数。由于const对象在调用成员函数的时候,会将this指针强行转换为const this,所以它将无法找到相应的const GetInt
函数,并且编译器也无法将一个const的对象转化为一个普通对象来调用这个普通的GetInt函数。
解决方法有:1、将const 限制去除。2、添加const 版本的GetInt函数
相关文章推荐
- The resolution of ERROR C2662: cannot convert 'this' pointer from "const Class-Type" to "Class&"
- error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’的解决办法
- error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’的解决办法
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’
- 网络安装出现错误 “unable to read package metadata.this may be due to a missing repodata directory”
- ASP.NET使用MySQL数据库得到错误Unable to find the requested .Net Framework Data Provider
- This application failed to start because it could not find or load the Qt platform plugin "xcb".
- ios错误<Error>: CGContextSaveGState: invalid context 0x0. If you want to see the backtrace, please set
- 错误:cannot convert 'QString' to 'const char*' for argument '1' to 'int system(const char*)'
- mysql错误1130,具体描述如下ERROR 1130 Host 'localhost' is not allowed to connect to this MySQL
- mysql数据库错误ERROR 1130:Host '' is not allowed to connect to this mysql server
- 错误:将'const x'作为'x'的'this'实参时丢弃了类型限定问题解决
- Unable to find a value for "Sex" in object of class ...错误
- qt程序运行在树莓派错误解决This application failed to start because it could not find or load the Qt platform plu
- jdbc连接mysql时报message from server: "Host '**' is not allowed to connect to this MySQL server"错误解决