#include<iostream>
using std::cout;
using std::endl;
class C
{
public:
int getX() const
{
this->x=12;//error C2166: 左值指定 const 对象
return this->x;
}
void setX(int x)
{
this->x=x;
}
private:
int x;
};
int main()
{
C c;
c.setX(10);
cout<<c.getX()<<endl;
return 0;
}
重学C++ const成员函数
最新推荐文章于 2022-06-26 09:49:32 发布
