常成员函数 int fun() const;

常成员函数不能改变数据成员!
 
 
 
#include <iostream>
using namespace std;

class Test {
private:
	int a;
public:
	int geta() {
		return a++;             //正确!
	}
	int getConst() const {
		return a++;		//错误!常成员函数不能改变数据成员。
	}
};

int main(void)
{
	return 0;
}
posted @ 2012-12-26 11:48  helloweworld  阅读(242)  评论(0编辑  收藏  举报