Is the following use of const_cast undefined behavior?
问题 This is a language lawyer question, not a good practice question. Is the following code valid or undefined behaviour? A const object ends up calling a non-const function, but it doesn't actually modify the state of the object. struct Bob { Bob() : a(0) {} int& GetA() { return a; } const int& GetA() const { return const_cast<Bob&>(*this).GetA(); } int a; }; int main() { const Bob b; int a = b.GetA(); } 回答1: The behavior is well-defined : C++ standard, section § 5.2.11/7 [const cast] [ Note: