Changing Function Access Mode in Derived Class
问题 Consider the following snippet: struct Base { virtual ~Base() {} virtual void Foo() const = 0; // Public }; class Child : public Base { virtual void Foo() const {} // Private }; int main() { Child child; child.Foo(); // Won\'t work. Foo is private in this context. static_cast<Base&> (child).Foo(); // Okay. Foo is public in this context. } Is this legal C++? \"This\" being changing the virtual function\'s access mode in the derived class. 回答1: Yes, changing the access mode in derived classes