Error C2662, cannot convert ‘this’ pointer from ‘const class ’ to ‘class &’的解决办法
解决方法帖子:
http://www.cnblogs.com/clever101/archive/2011/09/21/2184403.html
分析原因帖子:
http://blog.sina.com.cn/s/blog_60e96a410100n6ks.html
解决方法:
原因在于带const修饰符的接口会把this指针转化为为const this类型。网上一种解决办法是,把需要调用的非const接口都改为const,如上例的GetX、GetY和GetZ函数改为:
float GetX()
const{
return _x;}
float GetY() const{ return _y;}
float GetZ() const{ return _z;}
float GetY() const{ return _y;}
float GetZ() const{ return _z;}
我想到的一种办法是可以直接在内部将const修饰符去掉,具体如下: