Я пытался сделать предварительное объявление, чтобы разрешить доступ между классами. Я прочитал здесь, что:
- Я не могу включить файл "a.h" при прямом объявлении A в b.h
Мне не удалось найти много информации о пространствах имен во время предварительного объявления. И я совершенно уверен, что все испортил (я просто не знаю, куда их положить). Ошибки, которые я получаю, находятся после соответствующих фрагментов кода.
Вот что я сделал:
Я разделил определения своих классов от всех, находящихся в .h, до .cpp и .h.
У меня есть охранники #ifndef в моих файлах .h
Это мои файлы:
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(){....}
Ошибки для Form1.cpp То же самое для каждого определения
error C2872: 'GUI_1' : ambiguous symbol
could be 'GUI_1'
or OpenGLForm::GUI_1'
Форма1.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 — здесь нет ошибок
#include "stdafx.h"
#include "OpenGL.h"
#include "Form1.h"
OpenGLForm::COpenGL::COpenGL(){};
... other functions that go the same way
GUI_1.cpp — основная функция
#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;
}
Я собираюсь продолжать попытки расшифровать эти сообщения, но пока буду признателен за любую помощь.