How to access parent class's data member from child class, when both parent and child have the same name for the dat member

codeLover picture codeLover · Jul 17, 2012 · Viewed 32.1k times · Source

my scenario is as follows::

class Parent
{
public:
int x;
}

class Child:public Parent
{
int x; // Same name as Parent's "x".

void Func()
{
   this.x = Parent::x;  // HOW should I access Parents "x".  
}
}

Here how to access Parent's "X" from a member function of Child.

Answer

Luchian Grigore picture Luchian Grigore · Jul 17, 2012

Almost got it:

this->x = Parent::x;

this is a pointer.