C++ inherited class has member of same name

clamp picture clamp · Apr 13, 2010 · Viewed 16.3k times · Source

In C++ you can put a member in a base class and a member with the same name in the inherited class.

How can I access a specific one in the inherited class?

Answer

Kirill V. Lyadvinsky picture Kirill V. Lyadvinsky · Apr 13, 2010

In that case you should fully qualify a member name.

class A
{
public:
  int x;
};


class B : public A
{
public:
  int x;
  B() 
  { 
    x = 0;
    A::x = 1;
  }
};