What is the use of const overloading in C++?

It's there so you can make the compiler enforce whether you return a const object or a regular one, and still maintain the same method signature. There's an in-depth explanation at Const Correctness.


This really only makes sense when the member function returns a pointer or a reference to a data member of your class (or a member of a member, or a member of a member of a member, ... etc.). Generally returning non-const pointers or references to data members is frowned upon, but sometimes it is reasonable, or simply very convenient (e.g. [] operator). In such cases, you provide a const and a non-const versions of the getter. This way the decision on whether or not the object can be modified rests with the function using it, which has a choice of declaring it const or non-const.