繁体   English   中英

看不到包含的头文件

[英]Included header file is not being seen

编辑:新文件。 我在访问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也不起作用。

看起来您在OpenGL.h和Form1.h之间具有循环依赖关系

如果可以,请尝试删除#include "Form1.h" ,或将其转换为class Form1;的前向声明class Form1;

另外,在标头中using namespace时要小心,因为它会污染随后包含在其中的任何文件的名称空间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM