2012-07-13 4 views
0

편집 : 새 파일. Form1 클래스의 공용 함수에 액세스하는 데 문제가 있습니다. 내가 그것을 사용하려고하면 식별자를 찾을 수 없습니다. 를 Form1 :포함 된 헤더 파일이 보이지 않습니다.

#pragma once 

#include "OpenGL.h" 
#include "serialcom.h" 
#include "calculations.h" 

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; 
    using namespace OpenGLForm; 


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

    public ref class Form1 : public System::Windows::Forms::Form 
    { 
    public: 
     Form1(void) 
     { 
      InitializeComponent(); 
      OpenGL = gcnew COpenGL(this->panel4, this->label16, 785, 530); 
     } 
     void changelabel2(float num) 
     { 
      label2 -> Text = " " + num; 
     } 
    protected: ... 

OpenGL.h :

#include "stdafx.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 
... 

using namespace System::Windows::Forms; 

namespace OpenGLForm 
{ 
    public ref class COpenGL: public System::Windows::Forms::NativeWindow 
    { 
    public: 

     COpenGL(System::Windows::Forms::Panel^parentForm, System::Windows::Forms::Label^lbl, GLsizei iWidth, GLsizei iHeight) 
     { 
      CreateParams^ cp = gcnew CreateParams; 

      c_p_v v1, v2; 
      changelabel2(189); 
... 

그래서 문제가 해결되지 않는 ("changelabel2"에서 위). 클래스 이름을 사용하지 않았기 때문에 아마도?

이 내 주입니다 :

#include "stdafx.h" 
#include <string.h> 
#include <iostream> 
#include <stdio.h> 
#include <vcclr.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <vcclr.h>  
#include "Form1.h" 
#include "calculations.h" 
#include "serialcom.h" 

using namespace GUI_1; 

[STAThreadAttribute] 
int main(array<System::String ^> ^args) 
{ 
    // Enabling Windows XP visual effects before any controls are created 
    Application::EnableVisualStyles(); 
    Application::SetCompatibleTextRenderingDefault(false); 


    // Create the main window and run it 
    Form1^ form = gcnew Form1(); 
    Application::Run(form); 

    return 0; 
} 

호출 form.changelabel2 중 하나가 작동하지 않습니다.

답변

4

그것은 당신이 OpenGL.h와 Form1.h

사이의 순환 종속성 을 가지고있는 것처럼

#include "Form1.h" 할 수 있다면, 제거 또는 또한 class Form1;

처럼 앞으로 선언으로 변환 시도 할 때 조심 보인다 using namespace을 헤더에 사용하면 이후에 포함 된 파일의 네임 스페이스를 오염시킬 수 있습니다.

+0

감사합니다. 카일. 나는 지금 또 다른 문제가있다. 그리고 나는 여기서 먼저 시도 할 것이라고 생각했습니다. Form1 클래스에 public 함수가 있습니다.이 함수의 목적은 외부에서 호출하여 레이블을 업데이트하는 것입니다. 그러나, 내 OpenGL 클래스에 액세스 할 수없는 것 같습니다. 나는이 작은 창을 사용하기가 매우 어렵 기 때문에 아래에 추가 코드를 게시했다. – Mewa

+0

OpenGL 클래스는'#include "Form1.h가 없기 때문에 Form1 클래스에 액세스 할 수없는 것처럼 보입니다. 이것은 선언을 구현과 분리하는 이유 중 하나입니다 (일반적으로 .h 대 .cpp/.cc) . 헤더 파일에서 구현을 유지한다면 헤더 파일에'#include '가 필요없고 소스 파일에 (일반적으로) 아무런 이슈도 넣지 않기 때문에 원형 의존성없이 작업 코드를 작성하는 것이 훨씬 쉽습니다. – Kyle

관련 문제