使用 .inl 内联文件的前向声明不完整
Incomplete forward declaration using .inl inline files
希望标题没有误导。
我正在制作自己的线性代数数学库,只是为了练习和更好地理解数学编程。我使用 glm
数学库作为参考和帮助。我现在的类型是:
class Vector2, Vector3, Vector4
全部类表示float vectors(后面会是template
d)。
Vector2.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
后来 defined.This 一段代码给我 use of undefined type 'Vector3'
。据我所知,glm
正在做同样的事情,一切看起来都很好(glm
不包括 vec2
内的任何地方的 vec3
。 Here 是一个有用的 link,它帮助我更好地理解正在发生的事情,看起来它说的是同一件事,分开 declaration/definition 等等
我使用 VS Code Maps 对 glm
的包含和对 vec2
& vec3
的依赖进行了扩展搜索,但我找不到任何东西。我错过了什么?
编辑: 我主要关心的是 glm
如何执行我的代码试图执行的操作。我已经知道 "easy/right" 方式,但我想了解 glm
的代码。
我正在使用 c++11
+
据我搜索和理解,glm
使用前向声明。 type_vec.hpp
包含在每个 type_vecX.hpp
文件中,所有向量都有声明和 typedefs
(float
-bool
,high
-low
精度)line 103
。
诀窍是使用 template
s。首先我 template
d 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))
{}
希望标题没有误导。
我正在制作自己的线性代数数学库,只是为了练习和更好地理解数学编程。我使用 glm
数学库作为参考和帮助。我现在的类型是:
class Vector2, Vector3, Vector4
全部类表示float vectors(后面会是template
d)。
Vector2.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
后来 defined.This 一段代码给我 use of undefined type 'Vector3'
。据我所知,glm
正在做同样的事情,一切看起来都很好(glm
不包括 vec2
内的任何地方的 vec3
。 Here 是一个有用的 link,它帮助我更好地理解正在发生的事情,看起来它说的是同一件事,分开 declaration/definition 等等
我使用 VS Code Maps 对 glm
的包含和对 vec2
& vec3
的依赖进行了扩展搜索,但我找不到任何东西。我错过了什么?
编辑: 我主要关心的是 glm
如何执行我的代码试图执行的操作。我已经知道 "easy/right" 方式,但我想了解 glm
的代码。
我正在使用 c++11
+
据我搜索和理解,glm
使用前向声明。 type_vec.hpp
包含在每个 type_vecX.hpp
文件中,所有向量都有声明和 typedefs
(float
-bool
,high
-low
精度)line 103
。
诀窍是使用 template
s。首先我 template
d 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))
{}