Accessing parent's protected variables
<p>I couldn't think of a better wording for the title, so it is a little misleading, however, I am not talking about a child accessing its variables inherited from its parent, which is easy enough.</p>

<p>What I am talking about is this:</p>

<pre><code>class Parent {
  protected:
     Parent *target;
     int hp;
}

class Child : public Parent {
  public:
     void my_func();
}

void Child::my_func() {
    target-&gt;hp -= 50;
}
</code></pre>

<p>However, if I try to compile this, it will complain about 'hp' being "private in this context". The problem is that the child is not attempting to access its own parent's variables, but some other class', which may or may not be a Child itself.</p>

<p>An object can access all the variables and methods (public, protected, or private) of another object (two separate instances in memory) that is of the same class, so I thought that it would work with this as well, as it inherits from the class whose variables it's attempting to access, but it seems I was incorrect in assuming so.</p>

<p>Any tips?</p>

<p>P.S. Not to be rude or anything, but I know that I can just create get() and set() methods, but I was hoping for a cleaner way.</p>
