This question already has an answer here:
- C++ pure virtual function have body 3 answers
 
Here Base class had pure virtual function that has given its definition, I just want to invoke the function in main.Let me know the procedure, how can I invoke the same
#include<iostream>
    using namespace std;
    //Base class    
    class Base
    {
     int x;
     public:
     virtual void fun() = 0
     {
            cout<<"Base Class fun() is Called";
     }
     int getX()
     {
        return x;
     }
     };
    //Base end here
    //Derived class
     class Derived: public Base
     {
        int y;
        public:
        void fun()
        {
          cout << "Derived Class fun() called";
        }
        };
      int main(void)
      {
        Derived d;
        d.fun();
        //Calling Base Class Pure Virtual Function fun()
        Base::fun();
        return 0;
      }
Aucun commentaire:
Enregistrer un commentaire