在另一个头文件(C++)中包含头文件时遇到困难

在另一个头文件(C++)中包含头文件时遇到困难,c++,C++,嗨,我想把Toolkit.h加入到海王星行动中 工具箱库 动作功能 当代码运行时,Neptune Actions.h中的任何函数都不会被编译器识别,这意味着它没有收到Toolkit.h。为什么工具箱中的库在操作中不被识别?我错过了什么或做错了什么? 谢谢你的帮助 注意:同样的效果也发生在projectneptune.cpp中,但我认为这是因为操作无法检索工具包 海王星的行动如下。包括:init 此处,gl、gl代码产生以下错误示例: 1> c:\users\jjsun\source\repos\

嗨,我想把Toolkit.h加入到海王星行动中

工具箱库

动作功能

当代码运行时,Neptune Actions.h中的任何函数都不会被编译器识别,这意味着它没有收到Toolkit.h。为什么工具箱中的库在操作中不被识别?我错过了什么或做错了什么? 谢谢你的帮助

注意:同样的效果也发生在projectneptune.cpp中,但我认为这是因为操作无法检索工具包

海王星的行动如下。包括:init

此处,gl、gl代码产生以下错误示例:

1> c:\users\jjsun\source\repos\project neptune\project neptune\neptune actions.h79:错误C2065:“GL\u平滑”:未声明的标识符

1> c:\users\jjsun\source\repos\project neptune\project neptune\neptune actions.h79:错误C3861:'glShadeModel':找不到标识符

#ifndef Neptune Actions_H_INCLUDED
#define Neptune Actions_H_INCLUDED

// ToolKit not moving into both Source/Project
#include "Neptune ToolKit.h"
#include <iostream>

void init(void)
{
    // Clear Color + Shade Model
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glShadeModel(GL_SMOOTH);

    // Star Initialization
    glNewList(1, GL_COMPILE);
    glBegin(GL_POINTS);
    glColor3f(1.0, 1.0, 1.0);
    for (int i = 0; i < 200; i++) {
        for (int j = 0; j < 300; j++) {
            if (((i + j) % 2) == 0) {
                glVertex3f(100 * i, 100 * j, 0.0);
            }
        }
    }
    glEnd();
    glEndList();

    // Material Specs
    GLfloat mat_specular[] = { 0.8, 0.8, 0.9, 0.1 };
    GLfloat mat_shininess[] = { 128.0 };
    GLfloat lightDiffuse[] = { 1.0, 1.0, 1.0, 0.0 };
    GLfloat lmodel_ambient[] = { 0.1, 0.2, 0.7, 0.0 };

    // Light 0 Initialized.
    GLfloat light0[] = { 1.0, 1.0, 1.0, 0.1 };
    GLfloat light_position[] = { 1.0, 0.5, 0.0, -100.0 };

    // Light 1 Initialized 
    GLfloat light1[] = { 0.3, 0.2, 0.8 };
    GLfloat light_position1[] = { -0.3, 1.0, 0.3, -50.0 };

    GLfloat light2[] = { 1.0, 1.0, 1.0 };
    GLfloat light_position2[] = { 0.0, 0.0, 0.0, 0.0 };
    // Light 0
    glLightfv(GL_LIGHT0, GL_SPECULAR, light0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position);

    // Light 1
    glLightfv(GL_LIGHT1, GL_SPECULAR, light1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_position1);

    // Spotlight Light 2
    glLightfv(GL_LIGHT2, GL_SPOT_CUTOFF, light2);

    // Mat Specs Implmentations.
    glMaterialfv(GL_FRONT, GL_DIFFUSE, lightDiffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
    glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

    //Ambient surrounding light on object.
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

    // Enable Lighting and Depth
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    //glEnable(GL_LIGHT1);
    glEnable(GL_LIGHT2);
    glEnable(GL_DEPTH_TEST);

    // Enable AntiAliased Lines
    glEnable(GL_LINE_SMOOTH);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
    glLineWidth(1.5);
}
工具箱,见下文

#ifndef Neptune ToolKit_H
#define Neptune ToolKit_H

#include <iostream>
//GL/Windows
#include <Windows.h>
#include <GL/glew.h>
#include <GL/GL.h>
#include <GL/GLU.h>
#include <glut.h>
 //Texture 
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
 //Math
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

将您的Neptune Action.h头文件重命名为类似Neptune_Action.h的文件,然后更新您的头文件保护

stackoverflow.com上的所有问题必须以纯文本形式包含所有相关信息。使用纯文本读取器无法读取图像。你需要回答你的问题,并以纯文本形式显示所有相关信息。你的文件的实际确切名称是什么?您的防护罩中不应该有空间。定义Neptune ToolKit_H将用ToolKit_H替换所有提及的Neptune。使用单一标识符,如Neptune_ToolKit_H。可以自定义使用所有大写字母编写预处理器宏。如果在ifndef Neptune之后有一个额外的标识符也是不允许的,一些编译器太好了,不会抱怨错误,但可能是警告包含void initvoid定义的文件似乎是一个头文件。函数定义属于实现文件,而不是头文件。