#include <iostream> using namespace std; class Test { public: void fun1(); void fun1() const; }; void Test::fun1() { cout<<"normal member function"<<endl; } void Test::fun1() const { cout<<"const member function"<<endl; } int main() { cout << "Hello world!" << endl; Test t1; const Test t2; t1.fun1(); //访问普通成员函数 t2.fun1(); //访问常成员函数 const Test &t_r = t1; //对象常引用 t_r.fun1(); //访问常成员函数 const Test *t_p = &t1; //常指针(指针指向的对象是常对象) t_p->fun1(); //访问常成员函数 return 0; }