Monday, March 29, 2010

Private Virtual Functions ???

Q: If base class has public Virtual function and Derived has private function for same virtual .
Which function is called by base PTR pointing to derived ??
Ans : derived will get call , though it is private at derived
-----------------------------------------------------

----------------------
Output :
./a.out
derv1::f
derv2::f
--------------------------------------------
Q What if I have derived PTR and its pointing to Derived object and i call for VIRtual function??
Ans :  This will not get compiled 
 error: `virtual void der1::f()' is private

1 comment:

Followers