- struct A 类增加了一个toStr的方法,返回一个字符串,
-
class B 包含 struct A a;
- 结果一直报错
- 说是我无法把 struct A 对象 转为 const struct A & 对象。
- 查阅文章,发现,需要吧 toStr 方法声明为 toStr const 方法
常量的this指针
- C++,error c2662 cannot convert ‘this’ pointer from ‘const A’ to ‘A &’
- 大神指出,
- C++在调用类成员函数时会隐式的传递this指针 ,
- 将函数声明为const即相当于this指针被声明为const的,如下:
void print