#include<iostream> using namespace std; class A{ public: void func(int x, int y){ i = x; j = y; } void print()const{ cout << "i*j="<< i*j << endl; } private: int i, j; }; int main(){ A a; a.func(1, 2); a.print(); system("pause"); return 0; }
const成员函数:如果你不想让成员函数修改成员变量的值,就可以把成员函数声明为const
更多详情请点击 http://blog.sina.com.cn/zhaojianjunzjj