#include<iostream>
using namespace std;
class Derived;
class Base {
private:
virtual void fun() { cout << "Base Fun"; }
};
class Derived: public Base {
public:
void fun() { cout << "Derived Fun"; }
};
int main()
{
Base *ptr = new Derived;
ptr->fun();
return 0;
}
The above function gives the error:
virtual void Base::fun()’ is private within this context
But why does it need to check in the base class, while in the declaration we are making it clear that it's pointing to derived class?