我无法为它造出合适的词来称呼它,所以我就这样取了这个标题。
我有这个 DLL,其中template
dstruct
位于 a 中namespace
,其中定义了重载运算符struct
,这些运算符是这些s的非成员(自由函数) 。
“矢量X.h”
#ifdef SPECS
#define SPECS __declspec(dllimport)
#else
#define SPECS __declspec(dllexport)
#endif // SPECS
namespace swc
{
template <typename T>
struct Vec3 : Vec2<T>
{
Vec3();
Vec3(T value); //*1
Vec3& operator = (const T scalar); //*1
...
Vec3& operator += (const Vec3<T> &v);
Vec3& operator += (const T scalar);
//*1 w/c of this two are used when I do `Vec3<T> v = 0.0f;` ??
};
//What attribute should I use to make this works?
//It's compiling but it cause undefined reference when I use it.
//Or I have many ambiguous calls here(?)
template<typename T>
/* SPECS, static, extern */ Vec3<T> const operator * (const Vec3<T> &v, const T scalar);
template<typename T>
/* SPECS, static, extern */ Vec3<T> const operator * (const T scalar, const Vec3<T> &v);
typedef Vec3<float> Vec3f;
}
然后我尝试使用它
“测试.cpp”
#include <iostream>
#include "../../VectorX/vectorx.h"
using namespace swc;
Vec3f CalculateBezierPoint(float t, const Vec3f &p0, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3);
int main()
{
...
}
Vec3f CalculateBezierPoint(float t, const Vec3f &p0, const Vec3f &p1, const Vec3f &p2, const Vec3f &p3)
{
float u = 1 - t;
float tt = t * t;
float uu = u * u;
float uuu = uu * u;
float ttt = tt * t;
Vec3f p = uuu; //is it the operator '=' or the constructor Vec3f(T value)?
//**this is where the compiler starts complaining about undefined references.**
p += 3 * uu * t * p1;
p += 3 * u * tt * p2;
p += ttt * p3;
return p0;
}
这个有效p += 3 * 2 * 1;
,但这个无效p += 3 * 2 * 1 * p1;
我认为这是由于我在内部声明的自由函数的重载运算符namespace
导致了错误,但我不知道还能做什么。