Const casting empty base class
问题 Is it undefined behavior to const_cast away an empty base class and call a non const method on it? For example class EmptyBase { public: void bar() { ... } }; class Something : public EmptyBase { public: void foo() const { const_cast<EmptyBase&>(static_cast<const EmptyBase&>(*this)).bar(); } }; I haven't been able to find relevant information in the standards (C++14 and C++17) that answers this.. 回答1: It's not UB in and of itself. You get undefined behavior when you cast away constness and