Accessing members of parent class

Hi all,

I have a class A and class B. Class B inherits from A. Class A has a protected member x.

Class B has a method m which calls another method m1. In m1 I access A.x and set it to some value. The wierd thing is that when I try to access A.x in m after calling m1, it seems that A.x was not set at all.

I'd like to know if there's a proper way to access class A member x from B other than A.x.

Thanks in advance,
If I understand your question correctly then the problem with what you are doing is, you are using A.x to access x. However since B is inherited from A and x is a data member of A, so when you inherit B, A's data member will be inherited to B if the data members are public or protected. So to solve the problem instead of using A.x just use x

Hope this helps!
Sorry, it was a silly mistake!
Actually member x was a vetor<int> type. The fact was that inside method m1, I was redefining it through:

vector<int> x(n)

and what I intended to do was:

x = vector<int>(n);

Thank you for replying.
Topic archived. No new replies allowed.