i got this program is in http://www.parashift.com/c++-faq-lit...l-classes.html
the code is
It works and do not allow to instantiate the Leaf object.Code:#include <iostream> #include <memory> using namespace std; class Fred; class FredBase { private: friend class Fred; FredBase() {cout<<"FredBase Cons"<<endl; } }; class Fred : virtual private FredBase { public: Fred() { cout<<"Fred Cons"<<endl; } }; class Leaf : public Fred { }; int main() { Leaf f; return 0; }
I have confusion about the virtual keyword in (class Fred : virtual private FredBase )
why it is required.
If i remove the virtual keyword it is allowing me to create the Leaf f object.
What is the importance of virtual here ?




Reply With Quote