1,C++在定义函数重载的时候形参不管是不是const的他们都是等价的,除非形参是const引用。举个例子:

void fun(int a){...}与void fun(const int a){...}是等价的,这样重载会报错说redefinition。

void fun(int &a){...}与void fun(const int &a){...}这样就是正确的。

2,不能从const成员函数返回指向类对象的普通引用,const成员函数只能返回*this作为一个const引用。

const test_const &fun()const{...;return *this} //正确

test_const &fun()const{...;return *this} //错误

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-09-06
  • 2021-11-09
  • 2021-09-13
  • 2021-08-13
  • 2022-12-23
  • 2021-11-10
猜你喜欢
  • 2021-08-26
  • 2021-08-13
  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
相关资源
相似解决方案