C++/ur answer is like opposing multi level inheritence.
Expert: Eddie - 12/9/2004
QuestionMulti level inheritence should be a cumulative
thing,but your answer is opposing that.
explain me?.
--------------------------------------
Subject: in multiple inheritence at second level of hierarchy i could nt able to access base class memeber attribute.
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.
Eddie Answers -
Hello 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
AnswerHello again sadasivam, thanks for the question.
I never said anything opposing multi level inheritence. Because the class has derived from other derived classes, the variable i is ambiguous. Multi level inheritence it not a commonly used method. That's what I was stating. Hope this cleared things up for you.
I hope this information was helpful.
- Eddie