Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:52:52+00:00 2026-06-08T01:52:52+00:00

I have been trying to do forward declaration to allow access between classes. I

  • 0

I have been trying to do forward declaration to allow access between classes. I have read here that:

  • I can’t include the “a.h” file when forward declaring A in b.h

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.

This is what I did:

  • I have split my class definitions from all being in .h to .cpp and .h

  • I have #ifndef guards in my .h files

These are my files:

Form1.cpp

#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(){....}

Errors for Form1.cpp It’s the same thing for every definition

error C2872: 'GUI_1' : ambiguous symbol
could be 'GUI_1'
or       OpenGLForm::GUI_1'

Form1.h

#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;

    /// <summary>
    /// Summary for Form1
    /// </summary>

    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:
        ...
...};}

OpenGL.h

#ifndef opengl
#define opengl

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")

#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <math.h>

// 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

OpenGL.cpp – no errors here

#include "stdafx.h"
#include "OpenGL.h"
#include "Form1.h"

OpenGLForm::COpenGL::COpenGL(){};
... other functions that go the same way

GUI_1.cpp – the main function

#include <vcclr.h>
#include <stdio.h>
#include <stdlib.h>
#include "Form1.h"
#include "calculations.h"
#include "serialcom.h"
#include "OpenGL.h"

using namespace GUI_1;
using namespace OpenGLForm;

[STAThreadAttribute]
int main(array<System::String ^> ^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->o_gl = open_gl;
    // error C2143: syntax error : missing ';' before '->'

    open_gl->form1 = form1;
    // error C2059: syntax error : '='

    return 0;
}

I am going to keep trying to decypher these messages, but I’d appreciate any help meanwhile.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:52:53+00:00Added an answer on June 8, 2026 at 1:52 am
    • In OpenGL.h, you need to forward-declare Form1 in the correct namespace:

      namespace GUI_1 {
      ref class Form1;
      }

    • And forward-declare COpenGL in Form1.h the same way:

      namespace OpenGLForm {
      ref class COpenGL;
      }

    Important: Make sure these declareations are outside of other namespace blocks, and remove your existing forward-declarations from inside the classes.

    • In Form1.cpp, it would be clearer to define the member functions within a namespace block:

      namespace GUI_1 {
      Form1::Form1(void)
      …
      }

    • The two .cpp files include Form1.h and OpenGL.h in different orders. It would be better to only include Form1.h, and have Form1.h include OpenGL.h.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been trying to encrypt an xml file to a string so that I
I have been trying to find a collision avoidance example that I can adapt
I have been trying to create a ListView which I can sort using drag
I have been trying to serialize a list that contains arrays and lists. I
I have been trying to get the forward an back browser buttons to work
Have have been trying to make a validator for my xml files. I have
I have been trying to setup git for our web development team unsuccessfully. Some
I have been trying for almost a week now to create an SQLite database
I have been trying to generate report as per age differences of different months
I have been trying to align an entire label along with text to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.