What this C++ const-qualifier interview question tests
This is a medium-difficulty question that probes your understanding of C++ const semantics and how the compiler resolves member-function calls in the presence of const qualifiers. It's the kind of question that separates candidates who have read the standard from those who have only written code by intuition.
To work through this, you need to reason about const correctness rules: which functions can be called on const objects, how const and non-const overloads interact, and what the compiler's resolution order is when both versions exist. The question rewards careful reading of the code structure and a mental model of the compiler's overload-resolution process.
- const member functions vs. non-const member functions
- Overload resolution and const-correctness
- Binding temporary and const objects to function parameters