title: Visual C++/CLI mutual access between two class objects?
body: <p>Here is the problem:</p>
  
  <pre><code>namespace Program1 {
     public ref class Form1 : public System::Windows::Forms::Form
     {
      public: Form1(void) {....}
           private: RunnableThread^ peerThread;
  
     private: System::Void loginButton_MouseDown(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
      String^ ip = this-&gt;ipTextField-&gt;Text;
      String^ port = this-&gt;portTextField-&gt;Text;
          &lt;.............&gt;
          // Start new thread
          this-&gt;peerThread = gcnew RunnableThread("thread2", ip, port, this-&gt;gameMatrix, this);
          &lt;..............&gt;
      }
  }
  
     }
  
  
  // Runnable class
  ref class RunnableThread
  {
  private:
      String^ ip;
      String^ port;
      &lt;...&gt;
      EchoClient3WS::Form1^ refToRootObj;
      &lt;......&gt;
  public:
      RunnableThread(String^ threadName, String^ ip, String^ port, GameMatrix^ gameMatrix, Program1::Form1^ rootObj);
      void run();
      void callServer(String^ message);
      void done();
  };
  </code></pre>
  
  <hr>
  
  <p>And I got error:</p>
  
  <p>The line is:</p>
  
  <pre><code>'private: RunnableThread^ peerThread;'
  </code></pre>
  
  <p>Then error is:</p>
  
  <blockquote>
    <p>error C2146: syntax error : missing
    ';' before identifier
    'peerThread'  k:\visual studio
    2010\projects\program1\program1\Form1.h
    &lt;....></p>
  </blockquote>
  
  <hr>
  
  <p>It seems, that</p>
  
  <pre><code>namespace Program1 { public ref class Form: &lt;...&gt; {   
  // HERE WE DON'T KNOW ANYTHING ABOUT THE CLASS NAMED 'RunnableThread'
  
   } }
  </code></pre>
  
  <p>But I also can move the 'RunnableThread' declaration code before the 'namespace Program1', because the 'RunnableThread' uses pointer to father 'Form1' , who created an instance of this class.</p>
  
  <p>How to solve this problem?</p>
  
  <p>Thanks for any answer.</p>