title: C++/CLI Forward Declaration problems
body: <p>I have been trying to do forward declaration to allow access between classes. I have read here that:</p>
  
  <ul>
  <li>I can't include the "a.h" file when forward declaring A in b.h</li>
  </ul>
  
  <p>I haven't been able to find very much about namespaces during forward declaration. And I'm fairly certain I am messing this up (I just don't know where to put them). The errors I get are after the relevant code snippets.</p>
  
  <p>This is what I did:</p>
  
  <ul>
  <li><p>I have split my class definitions from all being in .h to .cpp and .h</p></li>
  <li><p>I have #ifndef guards in my .h files</p></li>
  </ul>
  
  <p>These are my files:</p>
  
  <p><strong>Form1.cpp</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include "OpenGL.h"
  #include "Form1.h"
  #include "serialcom.h"
  #include "calculations.h"
  
  using namespace GUI_1;
  
  GUI_1::Form1::Form1(void)
      {....
      }
  void GUI_1::Form1::chlabel2(float num)
      {....
      }
  int GUI_1::Form1::updateHand(int source){....}
  void GUI_1::Form1::resetHand(){....}
  </code></pre>
  
  <p><strong>Errors for Form1.cpp</strong> It's the same thing for every definition</p>
  
  <pre><code>error C2872: 'GUI_1' : ambiguous symbol
  could be 'GUI_1'
  or       OpenGLForm::GUI_1'
  </code></pre>
  
  <p><strong>Form1.h</strong></p>
  
  <pre><code>#ifndef form1
  #define form1
  
  using namespace OpenGLForm; 
  //error C2871: 'OpenGLForm' : a namespace with this name does not exist
  ref class COpenGL;
  
  namespace GUI_1 {
  
      using namespace System;
      using namespace System::ComponentModel;
      using namespace System::Collections;
      using namespace System::Windows::Forms;
      using namespace System::Data;
      using namespace System::Drawing;
  
      /// &lt;summary&gt;
      /// Summary for Form1
      /// &lt;/summary&gt;
  
      public ref class Form1 : public System::Windows::Forms::Form
      {
      public:
          OpenGLForm::COpenGL^ o_gl;
              // error C2653: 'OpenGLForm' : is not a class or namespace name
          Form1(void);
          void chlabel2(float num);
  
      protected:
          ...
  ...};}
  </code></pre>
  
  <p><strong>OpenGL.h</strong></p>
  
  <pre><code>#ifndef opengl
  #define opengl
  
  #pragma comment(lib, "opengl32.lib")
  #pragma comment(lib, "glu32.lib")
  
  #include &lt;windows.h&gt;
  #include &lt;GL/gl.h&gt;
  #include &lt;GL/glu.h&gt;
  #include &lt;GL/glut.h&gt;
  #include &lt;math.h&gt;
  
  // Declare globals
  
  ....
  
  namespace OpenGLForm 
  {
      using namespace System::Windows::Forms;
      using namespace GUI_1;
      // error C2871: 'GUI_1' : a namespace with this name does not exist
  
      ref class GUI_1::Form1;
      // error C2653: 'GUI_1' : is not a class or namespace name
      // 'Form1' uses undefined class 'OpenGLForm::GUI_1'
  
      public ref class COpenGL: public System::Windows::Forms::NativeWindow
      {
      public:
  
          Form1^ form1;
              // error C2059: syntax error : ';'
              // error C2238: unexpected token(s) preceding ';'
              // error C2143: syntax error : missing ';' before '^'
  
          ...
  };
  }
  #endif
  </code></pre>
  
  <p><strong>OpenGL.cpp - no errors here</strong></p>
  
  <pre><code>#include "stdafx.h"
  #include "OpenGL.h"
  #include "Form1.h"
  
  OpenGLForm::COpenGL::COpenGL(){};
  ... other functions that go the same way
  </code></pre>
  
  <p><strong>GUI_1.cpp - the main function</strong></p>
  
  <pre><code>#include &lt;vcclr.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include "Form1.h"
  #include "calculations.h"
  #include "serialcom.h"
  #include "OpenGL.h"
  
  using namespace GUI_1;
  using namespace OpenGLForm;
  
  [STAThreadAttribute]
  int main(array&lt;System::String ^&gt; ^args)
  {
      // Enabling Windows XP visual effects before any controls are created
      Application::EnableVisualStyles();
      Application::SetCompatibleTextRenderingDefault(false); 
  
      GUI_1::Form1 ^form1 = gcnew GUI_1::Form1();
      // error C2059: syntax error : '='
      OpenGLForm::COpenGL ^open_gl = gcnew OpenGLForm::COpenGL();
  
      form1-&gt;o_gl = open_gl;
      // error C2143: syntax error : missing ';' before '-&gt;'
  
      open_gl-&gt;form1 = form1;
      // error C2059: syntax error : '='
  
      return 0;
  }
  </code></pre>
  
  <p>I am going to keep trying to decypher these messages, but I'd appreciate any help meanwhile.</p>