If a private virtual function is overridden as a public function in the derived class, what are the problems?
问题 using namespace std; #include <cstdio> #include <iostream> class One{ private: virtual void func(){ cout<<"bark!"<<endl; } }; class Two: public One{ public: void func(){ cout<<"two!"<<endl; } }; int main(){ One *o = new Two(); o->func(); } Why is there an error on o->func() ? I don't know the mechanism behind it... In my opinion, o->func() should call the func() in the derived class, which is public, so there wouldn't be problems, but it says: error: ‘virtual void One::func()’ is private 回答1: