常成员函数 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;
}
原文地址:https://www.cnblogs.com/helloweworld/p/2833780.html