举个例子:

定义了一个类的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;
}

相关文章:

  • 2022-12-23
  • 2021-06-30
  • 2021-08-22
  • 2022-12-23
  • 2021-11-05
猜你喜欢
  • 2021-06-09
  • 2022-12-23
  • 2021-10-03
  • 2021-09-04
  • 2021-07-01
  • 2021-08-01
相关资源
相似解决方案