...

/

const and inout Member Functions

const and inout Member Functions

Get to learn about const and inout member functions in this lesson.

const member functions

Some member functions do not make any modifications to the object that they are called on. An example of such a function is toString():

struct TimeOfDay { 
// ...
    string toString() {
        return format("%02s:%02s", hour, minute); 
    }
// ...
}

Since the whole purpose of toString() is to represent the object in a string format anyway, it should not modify the object.

A member function that does not modify the object is declared by the const ...