【发布时间】:2017-07-09 16:33:46
【问题描述】:
我想在创建游戏对象时初始化转换变量,但是出了点问题。编译器说:
C3646 'transform' : unknown override specifier (line 4)
C4430 missing type specifier - int assumed. Note: C++ does not support default-int (line 4)
C3861 'Transform': identifier not found (line 5)
C2614 'GameObject' : illegal member initialization: 'transform' is not a base or member (line 5)
1. class GameObject
2. {
3. public:
4. Transform transform;
5. GameObject() : transform(Transform()) {}
6. };
7.
8. class Transform
9. {
10. public:
11. Vector3 position;
12. Vector3 rotation;
13. Vector3 dimension;
14.
15. Transform()
16. {
17. position = Vector3();
18. rotation = Vector3();
19. dimension = Vector3();
20. }
21. }
我在 main.cpp 中调用:
GameObject theGameObject = GameObject();
我做错了什么?
【问题讨论】:
-
您确实记得要能够使用一个符号,它必须在使用它之前声明或什至定义之前?所以尝试改变两个类定义的顺序,看看效果是否更好。
-
minimal reproducible example 总是一个很好的问题补充......
-
问题是GameObject类在GameObject.h中声明,Transform类在Transform.h GameObject.h中声明为#include "Transform.h",所以不知道怎么解决
-
已解决。我在“GameObject.h”中包含“Transform.h”,在 Transform.h 中包含“GameObject.h”,我觉得很愚蠢。谢谢
标签: c++ class constructor initialization