N
Naresh Agarwal
Hi
Class B
{
public :
virtual void foo()
{
// some impl
}
}
Class D : public B
{
private :
void foo()
{
// some impl
}
}
void main()
{
B *b = new D();
b->foo();
}
This program works fine!
So basically, we are able to access a private function of derived class
using a base class pointer. Why is it allowed in C++? Isn't it
voilation of encapsulation???
thanks & regards,
Naresh Agarwal
Class B
{
public :
virtual void foo()
{
// some impl
}
}
Class D : public B
{
private :
void foo()
{
// some impl
}
}
void main()
{
B *b = new D();
b->foo();
}
This program works fine!
So basically, we are able to access a private function of derived class
using a base class pointer. Why is it allowed in C++? Isn't it
voilation of encapsulation???
thanks & regards,
Naresh Agarwal