이 링크 오류를 이해할 수 없습니다. 는 I 2 개 클래스 가지고이 링크 오류를 이해할 수 없습니다.
#include "Vector3.h"
#include "Quaternion.h"
template<typename T>
class Point3 final
{
public:
constexpr Point3(const Vector3<T>& vec)
: x(vec.x), y(vec.y), z(vec.z)
{}
constexpr operator const Vector3<T>() const
{
// It is the equivalent of Vector3 = Point3 - Origin
return Vector3<T>(x, y, z);
}
constexpr operator Vector3<T>() const
{
// It is the equivalent of Vector3 = Point3 - Origin
return Vector3<T>(x, y, z);
}
T x = T(0);
T y = T(0);
T z = T(0);
friend Vector3<T>;
friend Quaternion<T>;
friend Vector3<T> operator*(const Quaternion<T>& lhs, const Vector3<T>& rhs);
friend Vector3<T> operator*(Vector3<T> lhs, const Vector3<T>& rhs);
};
typedef Point3<Float32> Point3f;
및
I 또한 상세히 내가 믿지 무관 쿼터니온 클래스가template<typename T>
class Vector3 final
{
public:
constexpr Vector3()
{}
constexpr Vector3(T _x, T _y, T _z)
: x(_x), y(_y), z(_z)
{}
T x = T(0);
T y = T(0);
T z = T(0);
};
typedef Vector3<Float32> Vector3f;
을하지만,이 클래스는 비 멤버 연산자 * 가지고
template<typename T>
Vector3<T> operator*(const Quaternion<T>& lhs, const Vector3<T>& rhs)
{
// nVidia SDK implementation
Vector3<T> qvec(lhs.x, lhs.y, lhs.z);
Vector3<T> uv = cross(qvec, rhs) * T(2.0) * lhs.w; //uv = qvec^v;
Vector3<T> uuv = cross(qvec, uv) * T(2.0); //uuv = qvec^uv;
return rhs + uv + uuv;
}
을 이제이 라인은 링크 오류를 발생 시키지만 왜 그럴까요? 여기
Math::Point3<Float32> pt = -Math::Point3<Float32>::UNIT_Z;
Math::Vector3<Float32> vec = orientation_*pt; // link error here (orientation is a Quaternion<Float32>)
//Math::Vector3<Float32> vec = orientation_*Math::Vector3<Float32>(pt); // this solve the link error.
링크 오류
Undefined symbols for architecture x86_64:
Math::operator*(Math::Quaternion<float> const&, Math::Vector3<float> const&), referenced from:
GfxObject::Procedural::BoxGenerator::addToTriangleBuffer(GfxObject::Procedural::TriangleBuffer&) const in ProceduralBoxGenerator.o
업데이트
나는이 정말 가까이하지만 문제가 차이 의존이 질문을 발견합니다. 에서
: question 1 및 question 2
하지만 내 경우에는 내가 2 개 템플릿 클래스 대신 같은 클래스 만 2 instantions 사이의 변환이 필요 . 이게 도움이되기를 바랍니다!
friend Vector3<T> operator* <> (const Quaternion<T>& lhs, const Vector3<T>& rhs);
이 일반적인 실수는 C++ FAQ here에 설명되어 있습니다 : 확인하는
당신은 ** 두 가지 클래스와 Quaternion 클래스를 가지고 있지 않습니다 **. 3 개의 ** 템플릿 **이 있습니다. –
템플릿 화 된'operator *'를 적어도 하나 이상 인스턴스화해야합니다. 그것은 소스 파일에 포함 된 헤더 파일에 포함되거나'operator * '를 포함하는 소스 파일에서 명시 적으로 인스턴스화되어야합니다. –
@PeteBecker 예 3 개의 템플릿 클래스가 있습니다. 그러나 나는이 문제가 2 개의 템플릿 클래스 인 Vector3와 Point3에서 발생한다고 믿습니다. – monamimani