Virtual function declared in a derived class
问题 Here I have declared another virtual function in Derived class. #include <iostream> using namespace std; class A{ string s; public: A(const string& name) : s(name){} virtual void f1(){cout << "f1 of base class" << endl;}; }; class B : public A{ string p; public: B(const string& name) : A(name){} virtual void f2(){cout << "virtual function of derived class" << endl;} void f1(){cout << "f1 of derived class";} }; int main() { A* arr[] = {new A("John"),new B("Bob")}; arr[0]->f1(); arr[1]->f1();