what is the purpose of having the leftmost 'const'?
When do we need to use two 'const' in defining the function?
Is there a rule?
TKS!
what is the purpose of having the leftmost 'const'?
When do we need to use two 'const' in defining the function?
Is there a rule?
TKS!
The const on the left is a return value to be a const and right says the member function is const.
A const return value is needed for temporary object allocation by the compiler. You never see them the compiler decides when needed but since they are temporary and you can't access them so they must be const. One use is overloaded operators that return non-lvalues. An lvalue indicates it can be on the left side of an assignment operator indicating it is modifiable. A non-lvalue is not modifiable so making them const is no loss but it does allow the compiler to create temporary objects.
A const member function says the funtion will not modify any members in the class.
Exept the ones marked mutable....