命名空间、类和编译器顺序
Namespace, class and compiler order
我正在使用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
是编译器的保留名称(以_
加大写字母开头),不应该被库或程序代码使用。
相关文章:
- C/C++编译器通常会删除重复的库吗
- CMake-按正确顺序将项目与C运行时对象文件链接
- C++编译器是否优化了顺序静态变量读取?
- 如何使C++编译器遵循与C#在该赋值语句中相同的优先级、关联性和求值顺序
- 编译器是否会简化按顺序执行多次的操作
- 编译器在遇到提取或插入运算符时处理信息(字符串、操纵器等)的顺序是什么?
- 如何不指定函数参数的精确求值顺序有助于C&C++编译器生成优化的代码?
- 编译器是否按照编写它们的顺序放置 && 语句的子句?
- VC++编译器输出顺序
- 更改编译器标志的顺序
- 类中方法声明的顺序是否对编译器很重要
- 编译器能否正确处理静态变量的初始化顺序?
- 使用编译器生成的默认初始化的成员初始化顺序
- 用于顺序内存访问的编译器嵌套循环优化
- 为什么在本例中,模板参数的顺序对MS C++编译器很重要
- 为什么 clang 编译器标志的顺序会影响生成的二进制大小
- CMake链接opencv两次打乱编译器命令顺序
- 函数调用的顺序.它是编译器还是取决于情况
- 编译器如何决定导入表中函数的顺序
- 命名空间、类和编译器顺序