Multiple Inheritance: same variable name

Jack Smother
class A
{
   protected:
    string word;
};

class B
{
   protected:
    string word;
};

class Derived: public A, public B
{

};

How would the accessibility of the variable word be affected in Derived? How would I resolve it?

Yochai Timmer

It will be ambiguous, and you'll get a compilation error saying that.

You'll need to use the right scope to use it:

 class Derived: public A, public B
{
    Derived()
    {
        A::word = "A!";
        B::word = "B!!";
    }
};

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Java inheritance confusion, superclass and subclass member variable having same name

From Dev

C# Multiple Interface Inheritance does not allow public access modifier with same name

From Dev

Duplicated variable because of multiple inheritance

From Dev

Move multiple pictureboxes at once of the same variable name C#

From Dev

C++ Inheritance of functions with same name

From Dev

Variable and constant with same name

From Dev

Variable Declarations with Same Name

From Dev

Same variable, different name

From Dev

Multiple parameters by the same name

From Dev

Multiple functions with the same name

From Dev

Multiple divs with same name

From Dev

Multiple inputs with same name

From Dev

Multiple templated interface inheritance name hiding

From Dev

Java multiple inheritance duplicate variable declaration?

From Dev

Python: function and variable with same name

From Dev

Python: function and variable with the same name

From Dev

Declaring two variable with the same name

From Dev

Swift, variable with same as a method name

From Dev

Using @ and $ with the same variable name in Perl

From Dev

Variable with same name in subclass and superclass

From Dev

Inherit same variable but different name

From Dev

R: variable and function of same name

From Dev

variable and function with same name clobbering

From Dev

Declarations of a class name and a variable with the same name

From Dev

Use a class name to call variable of the same name

From Dev

Use a class name to call variable of the same name

From Dev

Can class name and variable name be same in java?

From Dev

Is it OK to name a variable with the same name as a structure tag?

From Dev

Multiple EJB beans with same name

Related Related

HotTag

Archive