What does the trailing const in double area() const; promise in C++?
Correct answer
D. The function cannot modify the object's members
16 views
D. The function cannot modify the object's members
16 views
A const member function treats this as a pointer to const, so member variables cannot be assigned inside it unless they are marked mutable. The promise matters because it allows the function to be called on const objects and const references, which is why accessors such as getters are declared const. Trying to modify a member in such a function is a compile-time error, not a run-time check.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is D? Ask here and get an explanation.