Practice mode C++

Inside a const member function of a class, which data members can be modified?

Correct answer A. Only members declared mutable

Explanation

In a const member function, this points to a const object, so ordinary non-static data members are read-only. Members declared mutable are an exception and may be modified, which suits caches, lazy computations or mutex members that do not affect the object's logical state. Static data members are not part of the object, so const does not restrict them.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

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

Links and website addresses are not allowed in comments.