J
John Doe
I am using the free bcc compiler and was playing with partial ts:
below works ok:
template<unsigned M=3, unsigned N=3, typename T=double>
class Matrix
{
public:
Matrix() { _data=new T[M*N]; }
~Matrix() { delete [] _data; }
T& operator() (unsigned row, unsigned col)
{ return _data[row*M+col]; }
T operator() (unsigned row, unsigned col) const
{ return _data[row*M+col]; }
private:
T* _data;
};
template<unsigned M, unsigned N, typename T>
class Matrix<3,3,T>
{
public:
Matrix() { _data=new T[9]; }
~Matrix() { delete [] _data; }
T& operator() (unsigned row, unsigned col)
{ return _data[row<<1+col]; }
T operator() (unsigned row, unsigned col) const
{ return _data[row<<1+col]; }
private:
T* _data;
};
but if I try to put member definitions into another file say matrix.cpp
like this
template<unsigned M, unsigned N, typename T>
Matrix<3,3,T>::Matrix() {}
it just doesnt work + the compiler sometimes decides a function should be
inline when I don't want it to be and linking with the .obj containing
inlined functions does not work.
below works ok:
template<unsigned M=3, unsigned N=3, typename T=double>
class Matrix
{
public:
Matrix() { _data=new T[M*N]; }
~Matrix() { delete [] _data; }
T& operator() (unsigned row, unsigned col)
{ return _data[row*M+col]; }
T operator() (unsigned row, unsigned col) const
{ return _data[row*M+col]; }
private:
T* _data;
};
template<unsigned M, unsigned N, typename T>
class Matrix<3,3,T>
{
public:
Matrix() { _data=new T[9]; }
~Matrix() { delete [] _data; }
T& operator() (unsigned row, unsigned col)
{ return _data[row<<1+col]; }
T operator() (unsigned row, unsigned col) const
{ return _data[row<<1+col]; }
private:
T* _data;
};
but if I try to put member definitions into another file say matrix.cpp
like this
template<unsigned M, unsigned N, typename T>
Matrix<3,3,T>::Matrix() {}
it just doesnt work + the compiler sometimes decides a function should be
inline when I don't want it to be and linking with the .obj containing
inlined functions does not work.