title: C++: Accessing the parent class from a child-class
body: <p>I have two classes:</p>
  
  <pre><code>class ClassA {
      public:
          ClassB *classB;
          int i = 100;
  }
  // and:
  class ClassB {
      public:
          void longProcess();
  }
  </code></pre>
  
  <p>I run a void from ClassB():</p>
  
  <pre><code>ClassA classA = new ClassA();
  classA-&gt;i = 100;
  classA-&gt;classB = new ClassB();
  classB-&gt;longProcess(); // it's a long process!
  // but when it will finish - I need to get the "i" variable from ClassA
  </code></pre>
  
  <p>How do I get the "int i" variable from the method: longProcess()? Actually, I need to running this long code in another thread that's why I need to retrieve the "i" variable from the ClassB when the longProcess() will finished its work. Any suggestions?</p>
  
  <p><strong>Update: I try to write some code for saving the pointer to the parent class</strong> </p>
  
  <p>//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ ChildClass.h ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=</p>
  
  <pre><code>#include "ParentClass.h"
  class ChildClass {
      public:
          ChildClass();
          ParentClass *pointerToParentClass; // ERROR: ISO C++ forbids declaration of 'ParentClass' with no type
          void tryGet_I_FromParentClass();
  };
  </code></pre>
  
  <p>ERROR: ISO C++ forbids declaration of 'ParentClass' with no type</p>
  
  <p>//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ ChildClass.cpp ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=</p>
  
  <pre><code>#include "ChildClass.h"
  ChildClass::ChildClass(){}
  void ChildClass::tryGet_I_FromParentClass(){
      // this-&gt;pointerToParentClass...??? it's not work
  }
  </code></pre>
  
  <p>//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ ParentClass.h ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=</p>
  
  <pre><code>#include "ChildClass.h"
  class ParentClass {
      public:
          ParentClass();
          ChildClass *childClass;
          int i;
  };
  </code></pre>
  
  <p>//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ ParentClass.cpp ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=</p>
  
  <pre><code>#include "ParentClass.h"
  ParentClass::ParentClass(){
      childClass = new ChildClass();
      childClass-&gt;pointerToParentClass = this;
  }
  </code></pre>
  
  <p>//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=[ MainWindow.cpp ]-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=</p>
  
  <pre><code>ParentClass *parentClass = new ParentClass();
  </code></pre>