Hello,
if a simple inheritance is there i am able to know as to which class should i declare as virtual!but when 6,7 classes are involved i get confused. Here is the code which i am posting
Here which classes should be declared as virtual ??i mean i know if i put the keyword virtual before B in class C declaration and in class E declaration i get no error. But how?????Code:#include <iostream.h> class A { protected: int a; }; class B:public A { protected: int b; }; class C:public B { protected: int c; }; class D:public C { protected: int d; }; class E:public D { protected: int e; }; class F:public B,public E { protected: int f; public: void putdata() { cout<<a<<endl; cout<<b<<endl; cout<<c<<endl; cout<<d<<endl; cout<<e<<endl; cout<<f<<endl; } }; int main(void) { F f; return 0; }
Please state the reason and also explain me how to detect which class should be declared as virtual in complex derivation?
In the above derivation even A is inherited twice then why have we not declared A as virtual? please provide a detailed yet simple to understand explanation