c++ const 成员函数

来源:互联网 发布:mac官网下载地址 编辑:程序博客网 时间:2024/04/30 09:52

const对象不能调用非const成员函数

 

vc2005提示错误为:

error C2662: 'test::getval' : cannot convert 'this' pointer from 'const test' to 'test &'

说明成员函数的this指针类型为test * 或test & 不能由const test * 或const test赋值.

 

解决方法:

getval加上const属性或者对a进行const_cast .

 

 

原创粉丝点击