![](/img/trans.png)
[英]I need to include two header files to each other not using forward declaration cause get “incomplete type” error
[英]Incomplete forward declaration using .inl inline files
我希望标题没有误导。
我正在制作自己的线性代数数学库,只是为了练习和更好地理解数学编程。 我使用glm
数学库作为参考和帮助。 我现在的类型是:
class Vector2, Vector3, Vector4
所有类都表示浮点向量(稍后将是template
d)。
矢量2.h
#include <SomeGenericMathFunctions.h>
//Forward Declare Vector3
struct Vector3;
struct Vector2
{
public:
float X, Y;
//Constructors
//Constructor in question
Vector2(const Vector3 & inVec3);
//Functions
//Operators
};
#include <Vector2.inl>
Vector2.inl
//Inline Constructor definitions
.
.
.
//Constructor in question
inline Vector2::Vector2(const Vector3 & inVec3) : X(inVec3.X), Y(inVec3.Y)
{}
//Functions & operators definitions
Vector3
是稍后定义的。这段代码让我use of undefined type 'Vector3'
。 据我所知, glm
正在做同样的事情,一切看起来都很好( glm
不包括vec3
内的任何地方vec2
)。 这是一个有用的链接,它帮助我更好地理解正在发生的事情,看起来它说的是同样的事情,单独的声明/定义等。
我使用 VS Code Maps 对glm
的包含和对vec2
和vec3
的依赖项进行了扩展搜索,但我找不到任何东西。 我错过了什么?
编辑:我主要关心的是glm
如何做我的代码试图做的事情。 我已经知道“简单/正确”的方式,但我想了解glm
的代码。
我正在使用c++11
+
据我搜索并了解glm
使用前向声明。 type_vec.hpp
包含在每个type_vecX.hpp
文件中,在line 103
有所有向量的声明和typedefs
( float
- bool
, high
- low
精度)。
诀窍是使用template
。 首先,我template
了structs
template<typename T>
struct Vector2
{
public:
...
};
对于有问题的构造函数,变化是
宣言:
template<typename S>
Vector2(const Vector3<S> & inVec3);
定义
template <typename T>
template <typename S>
inline Vector2<T>::Vector2(const Vector3<S> & inVec3) :
X(static_cast<T>(inVec3.X)),
Y(static_cast<T>(inVec3.Y))
{}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.