Hello
I wanted to understand a contradictory design of C++
class A
{public:
virtual void f(){ cout<<" base f"<<endl; }
};
class B:public A
{
private:
void f(){ cout<<"private derived B f"<<endl;};
};
main()
{
B b;
A* p = &b;
p->f();
}
why does the compiler allows me to call a private function in B though
accessing it directly is not possible;(B b; b.f() gives error)
Vijay
I wanted to understand a contradictory design of C++
class A
{public:
virtual void f(){ cout<<" base f"<<endl; }
};
class B:public A
{
private:
void f(){ cout<<"private derived B f"<<endl;};
};
main()
{
B b;
A* p = &b;
p->f();
}
why does the compiler allows me to call a private function in B though
accessing it directly is not possible;(B b; b.f() gives error)
Vijay
Comment