C++/in multiple inheritence at second level of hierarchy i could nt able to access base class memeber attribute.
Expert: Eddie - 12/9/2004
Question#include<iostream.h>
class base{
public:
int i;
};
class derived1: public base
{
public :
int j;
};
class derived2: public base
{
public:
int k;
};
class derived3:public derived1,public derived2 {
public :
int sum;
};
void main()
{
derived3 ob;
base o;
derived1 d1;
ob.base::i=10;//Error
ob.derived1::i=20;//It works fine
ob.derived2::i=30;//It works fine
}
Error: 'base' is not a public base class of 'derived3'
Question:
Why i coud not able to acces CLASS 'base' i-(ob.base::i) via CLASS 'derived3' object. Here i think CLASS 'derived' will have two i's one from derived1 and from derived2(virtul class concept).My question is not about virtual class concept.why such error?
compiler:
Turboc++
versio 3.0
from Borland internationl.
AnswerHello sadasivam, thank you for the question.
Yeah, you can't do that. This is why inheritence usually stops after the first level of inheritence. Remember, the third level derived object does not "know" that it has a grandparent class. That's the reason for your error.
I hope this information was helpful.
- Eddie