-1
class StatDemo
{
} ;
private:
static int x;
int y;
public:
void setx(int a) const { x = a; }
void sety(int b) const { y = b; }
int getx() {return x; }
int gety() {return y; }
当成员变量被函数改变时,const的用法是什么?当函数改变成员变量时,给定函数中const的用法是什么?
“什么是const的使用...”导致编译器错误? – songyuanyao
看起来你错误地让setter为const,而getters为非const。它应该是相反的。这些东西都应该放在类的定义里面,而不是放在后面。 – paddy