怎么在const成员函数里面调用非const成员函数?

举个例子:

定义了一个类的const实例,怎么让他也能调用非能调用非const成员函数
class foo{
public:
void test1()

{
cout << "I am not a const member function" << endl;
}
void test2()const

{
foo *temp = (foo*)this;//注意这个转换!!!
temp->test1();
}
};

int main()

{
foo f;
f.test2();
return 0;
}

posted on 2015-08-26 17:26  lpx15312  阅读(639)  评论(0编辑  收藏  举报

导航