C++ cosnt的一点总结

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} //错误

原文地址:https://www.cnblogs.com/ymy124/p/3640706.html