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

时间:2015-05-18 18:25:31

标签: c++ class header namespaces

我正在使用OpenGL,我构建并编辑了一个可以与struct Vector3一起使用的完美工作的Vector3标题,但是当我尝试创建一个Vector3 zero = Vector3(0,0,0)变量,编译器没有& #39; t由于编译顺序让我构建,所以我从Internet复制了一个新的Vector3库,我收到了这个错误:"Vector3 does not name a type"。我想是因为编译的顺序,我将分享我得到错误和库的地方。首先,这是我使用http://leetnightshade.com/c-vector3-class的2个文件我只使用了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;

专注于4行struct GameObject,这是我在Vector3位置得到错误的地方;线。我想我正确地解释了自己。如果你不太了解http://gyazo.com/77189bef5576b047de5271f1b7d2d881,我就制定了一个计划。感谢阅读。

1 个答案:

答案 0 :(得分:1)

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

_Warp::Vector3 position;

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

相关问题