Const Member Functions

void const f() is equivalent to const void f(), which means the return type (in this case a void) is const. This is totally meaningless not only because it’s a void (there is nothing there that needs a const qualifier), but also because it’s a return type (returning something as const doesn’t make a whole lot of sense).

void f() const makes the function itself const. This only really has meaning for member functions. Making a member function const means that it cannot call any non-const member functions, nor can it change any member variables. It also means that the function can be called via a const object of the class.

Member functions are const which means that they don’t change the state (data) of the object on which they act. This means that they can act on both const and non-const objects of that class.Not specifying a member function as const means that the member function can only be invoked for non-const objects which limits its use. So if a member function doesn’t change an object’s state then it should by definition be const.

Constant functions eventually leads to mutable keyword being added to the language.

Resolving technical problems:

Solve your technical problems instantly

We provide Remote Technical Support from Monday to Sunday, 7:00PM to 1:00 AM

Mail your problem details at writeulearn@gmail.com along with your mobile numberand we will give you a call for further details. We usually attend your problems within 60 minutes and solve it in maximum 2 days.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.