命名空间、类和编译器顺序

Namespace, class and compiler order

本文关键字:编译器 顺序 命名空间      更新时间:2023-10-16

我正在使用OpenGL,我构建并编辑了一个Vector3头,它可以完美地与结构体Vector3一起工作,但当我尝试创建Vector3 zero = Vector3(0,0,0)变量时,问题开始了,编译器不让我构建由于编译顺序,所以我从互联网上复制了一个新的Vector3库,我得到了这个错误:"Vector3 does not name a type"。我想这是因为编译的顺序,我将分享我在哪里得到错误和库。首先,这是我使用的2个文件http://leetnightshade.com/c-vector3-class我只使用Vector3.cpp和Vector3.h,这段代码是我做的,是我得到错误的地方(这是一个名为GameObject.h的main.cpp文件调用的头文件):

#include "Vector3.h"
GLfloat cube[] =
{
    -1.0f,-1.0f,-1.0f,
    -1.0f,-1.0f, 1.0f,
    -1.0f, 1.0f, 1.0f,
    1.0f, 1.0f,-1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f,-1.0f,
    1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f,-1.0f,
    1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f, 1.0f,
    -1.0f,-1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    -1.0f,-1.0f, 1.0f,
    1.0f,-1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f,-1.0f,
    1.0f,-1.0f,-1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f,-1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    1.0f, 1.0f,-1.0f,
    -1.0f, 1.0f,-1.0f,
    1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f,-1.0f,
    -1.0f, 1.0f, 1.0f,
    1.0f, 1.0f, 1.0f,
    -1.0f, 1.0f, 1.0f,
    1.0f,-1.0f, 1.0f
};
GLfloat Space3D_X[] =
{
    0.0f, 0.0f, -100,
    0.0f, 0.0f, 100
};
GLfloat Space3D_Y[] =
{
    -100.0f, 0.0f, 0.0f,
    100.0f, 0.0f, 0.0f
};
typedef struct GameObject
{
    int ID, parent;
    Vector3 position;  ///<<<--------------------------HERE I GET THE ERROR VECTOR3 DOES NOT NAME A TYPE
    Quaternion rotation;
};
struct GameObject GameObjects[65536];
class Natives
{
    public:
        int GameObjectsCount = 0;
        inline int CreateCube (Vector3 _position, Quaternion _rotation, int _parent)
        {
            GameObjects[GameObjectsCount].ID = GameObjectsCount;
            GameObjects[GameObjectsCount].parent = _parent;
            GameObjects[GameObjectsCount].position = _position;
            GameObjects[GameObjectsCount].rotation = _rotation;
            GameObjectsCount ++;
            return GameObjectsCount-1;
        }
        inline void SetGameObjectParent (int _gameObject, int _parent)
        {
            Vector3 _tempPos = GameObjects[_gameObject].position;
            Quaternion _tempRot = GameObjects[_gameObject].rotation;
            GameObjects[_gameObject].parent = _parent;                                               /*** ATTACH GM TO OTHER GM WITHOUT CHANGE POSITION ***/
            GameObjects[_gameObject].position.x = -(GameObjects[_parent].position.x - _tempPos.x);   /*** IF YOU WANT TO ATTACH IT CHAING POSITION JUST ***/
            GameObjects[_gameObject].position.z = -(GameObjects[_parent].position.z - _tempPos.z);   /***     OVERWRITE THE PARENT WITH OOP SYNTAX      ***/
            GameObjects[_gameObject].rotation.rx = _tempRot.rx;
            GameObjects[_gameObject].rotation.ry =  _tempRot.ry;
            GameObjects[_gameObject].rotation.rz =  _tempRot.rz;
        }
};
Natives native;

专注于结构GameObject的4行,这是我在Vector3位置得到错误的地方;线。我想我解释得没错。我做了一个方案,如果你不明白http://gyazo.com/77189bef5576b047de5271f1b7d2d881。

您链接的Vector3库使用名称空间_Warp,因此您应该这样使用它:

_Warp::Vector3 position;

PS:要警惕任何使用保留名作为标识符的第三方库,因为编写者可能不知道他们在做什么。_Warp是编译器的保留名称(以_加大写字母开头),不应该被库或程序代码使用。