如果数据类型不是vec3
类型,我想创建一个使用常规vec3
类(非SIMD
)类的float
类,并使用数据类型vec3
的{{1}}(SIMD
)优化类。我坚持如何正确使用模板专业化。
问题出在移动构造函数中,但我开始怀疑是否可能使用模板特化来移动构造函数。
注意:我使用的是float
错误
CLion
vec3.h
C:\Users\Matt\AppData\Local\JetBrains\Toolbox\apps\CLion\ch-0\171.4694.31\bin\cmake\bin\cmake.exe --build C:\Users\Matt\CLionProjects\RainyDayEngine\cmake-build-debug --target RainyDayEngine -- -j 8
Scanning dependencies of target RainyDayEngine
[ 10%] Building CXX object CMakeFiles/RainyDayEngine.dir/main.cpp.obj
[ 20%] Building CXX object CMakeFiles/RainyDayEngine.dir/Engine/Core/Math/vec3.cpp.obj
In file included from C:\Users\Matt\CLionProjects\RainyDayEngine\Engine\Core\Math\vec3.cpp:5:0:
C:\Users\Matt\CLionProjects\RainyDayEngine\Engine\Core\Math\vec3.h:63:31: error: declaration of 'vec3<T>::vec3(vec3<T>&&)' has a different exception specifier
vec3<T>::vec3 (vec3<T> &&other)
^
C:\Users\Matt\CLionProjects\RainyDayEngine\Engine\Core\Math\vec3.h:34:2: error: from previous declaration 'vec3<T>::vec3(vec3<T>&&) noexcept'
vec3(vec3<T>&& other) noexcept;
^
CMakeFiles\RainyDayEngine.dir\build.make:262: recipe for target 'CMakeFiles/RainyDayEngine.dir/Engine/Core/Math/vec3.cpp.obj' failed
mingw32-make.exe[3]: *** [CMakeFiles/RainyDayEngine.dir/Engine/Core/Math/vec3.cpp.obj] Error 1
mingw32-make.exe[3]: *** Waiting for unfinished jobs....
In file included from C:\Users\Matt\CLionProjects\RainyDayEngine\main.cpp:6:0:
C:\Users\Matt\CLionProjects\RainyDayEngine\Engine/Core/Math/vec3.h:63:31: error: declaration of 'vec3<T>::vec3(vec3<T>&&)' has a different exception specifier
vec3<T>::vec3 (vec3<T> &&other)
^
C:\Users\Matt\CLionProjects\RainyDayEngine\Engine/Core/Math/vec3.h:34:2: error: from previous declaration 'vec3<T>::vec3(vec3<T>&&) noexcept'
vec3(vec3<T>&& other) noexcept;
^
CMakeFiles\RainyDayEngine.dir\build.make:62: recipe for target 'CMakeFiles/RainyDayEngine.dir/main.cpp.obj' failed
mingw32-make.exe[3]: *** [CMakeFiles/RainyDayEngine.dir/main.cpp.obj] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/RainyDayEngine.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/RainyDayEngine.dir/rule] Error 2
mingw32-make.exe: *** [RainyDayEngine] Error 2
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/RainyDayEngine.dir/all' failed
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/RainyDayEngine.dir/rule' failed
Makefile:117: recipe for target 'RainyDayEngine' failed
vec3_sse.h
template <typename T>
class vec3
{
public:
vec3();
vec3(T *pval);
vec3(T x, T y, T z);
vec3(const vec3<T>& other);
vec3(vec3<T>&& other) noexcept;
void print() { std::cout << "hello regular" << std::endl; }
protected:
struct {
T x, y, z;
};
};
template <typename T>
vec3<T>::vec3 ()
: x(0), y(0), z(0)
{}
template <typename T>
vec3<T>::vec3 (T *pval)
: x(pval[0]), y(pval[1]), z(pval[2])
{}
template <typename T>
vec3<T>::vec3 (T x, T y, T z)
: x(x), y(y), z(z)
{}
template <typename T>
vec3<T>::vec3 (const vec3<T> &other)
: x(other.x), y(other.y), z(other.z)
{}
template <typename T>
vec3<T>::vec3 (vec3<T> &&other)
: x(std::move(other.x)), y(std::move(other.y)), z(std::move(other.z))
{}