Why I am getting access-specifier error (private-member) for the following piece of code?
#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"; } //this should be called
};
int main()
{
Base *ptr = new Derived;
ptr->fun();
return 0;
}
Here, fun() of derived class should be called and since it is public, there should be no error.