It is well known that C + + classes implement function overloading in two cases: the type of the function parameter is different, the number of parameters is different. It has nothing to do with the return value of the function. There is also a class member function overload, which does not require a different parameter type for the function. Here's an example:
#include <iostream>using namespace Std;class a{public: A (int a): _a (a) {} void print () const// The data member object cannot be modified in the function body, otherwise the error { cout << const << _a << Endl; } void print ()//function body can modify member object { _a =; cout << "Non-const" << _a << Endl; } Private: int _a;}; int main () { a A (n); A.print ();//If none of the above Non-const overloads, then the const function const A b (n) is executed here; B.print (); return 0;}
The above code runs the result:
Non-const 23const 12
Therefore, class member function overloading is not an absolute parameter list in which parameter types must be different. Why is this possible? This actually involves the underlying implementation of the C + + object model. When these two functions of a class are compiled, their registered names are different and therefore can exist together.
Reprint please specify the source (http://blog.csdn.net/gulansheng/article/details/45827755)
C + + member functions const overloading