AAlkhabbaz
AAlkhabbaz

Reputation: 197

multiple inheritance with same attribute in super class

In multiple inheritance c++ with same attribute in suber class like this code

class A{
protected :
    int var;
}

class B{
protected :
    int var;    
}

class C: public A,B{

    C(){
        A::var=3;
        B::var=5;
    }
}

i must write A::var or B::var to determine the super class is there any way to redefine the attribute in C class like

#define AA = A::var

Upvotes: 2

Views: 1664

Answers (1)

valdo
valdo

Reputation: 12943

Surely you may #define everything. But this is not a good altitude. Also AA would be defined everywhere in your code, not only in the scope of class C.

You may add:

using A::var;

So that var would be A::var by default.

Besides of this you may add a member function that would return you a reference to your member variable, if you don't want to add A:: everywhere.

Upvotes: 2

Related Questions