Why below code gives error even if the public function in derived class is the one being called..?

41 Views Asked by At

In the following code a public function has overriden a private virtual function in base class ob->hello() shall call hello() in derived class which is public. why do i still see an error that hello() is private.

    ```
     #include<iostream>
     using namespace std;

     class base{
       private:
       virtual void hello();
     };

     class der: public base{
        public:
        void hello();
      }; 

      void der::hello(){
        cout<<"hi"<<endl;
      }    

      void base::hello(){
        cout<<"hello"<<endl;
      }

      int main(){
         base* ob = new der();
         ob->hello();
      }    
      ```
0

There are 0 best solutions below