函数后面还带有const是什么意思
int car::getMovedTimes()const
{
return movedTimes;
}
这个const代表什么意思啊
[解决办法]
不能修改成员变量,不能调用其他非const函数,const对象可以调用该函数。
举例:
class A {public: void Test2() { i = 6; //正确 } void Test() const { i = 5; //编译出错 Test2() //编译出错不能调用非const函数 }private : int i;};int main(void) {const A a;a.Test();a.Test2(); //错误const对象不能调用非const函数。return 0;}