S
Steven T. Hatton
Basically the question is, can I do this?:
template <typename T>
class Vector3 {
public:
Vector3(const T& x=0,
const T& y=0,
const T& z=0)
: _v(3)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
}
~Vector3()
{}
/*...*/
/** {1, 0 ,0} */
static const Vector3<T> I;
/** {0, 1 ,0} */
static const Vector3<T> J;
/** {0, 0 ,1} */
static const Vector3<T> K;
private:
vector<T> _v;
};
It works for non-template classes of the same form, but I keep getting
linker errors saying 'undefined reference to Vector3<float>I', etc.
This is what I currently have in the source file. I have no good reason to
believe it makes the least bit of sense, other than the fact the compiler
doesn't complain:
template<typename T>
const Vector3<T> Vector3<T>::I = Vector3<T>(1,0,0);
template<typename T>
const Vector3<T> Vector3<T>::J = Vector3<T>(0,1,0);
template<typename T>
const Vector3<T> Vector3<T>::K = Vector3<T>(0,0,1);
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell
template <typename T>
class Vector3 {
public:
Vector3(const T& x=0,
const T& y=0,
const T& z=0)
: _v(3)
{
_v[0]=x;
_v[1]=y;
_v[2]=z;
}
~Vector3()
{}
/*...*/
/** {1, 0 ,0} */
static const Vector3<T> I;
/** {0, 1 ,0} */
static const Vector3<T> J;
/** {0, 0 ,1} */
static const Vector3<T> K;
private:
vector<T> _v;
};
It works for non-template classes of the same form, but I keep getting
linker errors saying 'undefined reference to Vector3<float>I', etc.
This is what I currently have in the source file. I have no good reason to
believe it makes the least bit of sense, other than the fact the compiler
doesn't complain:
template<typename T>
const Vector3<T> Vector3<T>::I = Vector3<T>(1,0,0);
template<typename T>
const Vector3<T> Vector3<T>::J = Vector3<T>(0,1,0);
template<typename T>
const Vector3<T> Vector3<T>::K = Vector3<T>(0,0,1);
--
"If our hypothesis is about anything and not about some one or more
particular things, then our deductions constitute mathematics. Thus
mathematics may be defined as the subject in which we never know what we
are talking about, nor whether what we are saying is true." - Bertrand
Russell