IT should never generate references to the uninstantiated template. If you want to use it however, the template has to be joined with the header or compiled separately (as export, which your compiler doesn't support).
I think it might be a side-effect of how you invoke the compiler.
In general it is bad practice to separate a template declaration and implementation in a h and c file, just put them in one h file. Personally i prefer the separation in two files but it gives a lot of problems. Though i didn't check pragma interface and pragma implementation yet.
Seperating declaration and definition is not a bad idea at all, it is elementary to making C++ code maintainable.
The problem is that a template definition can only be made into code if the compiler "knows" the actual type with which to instantiate the template. There are ways around it, which is why the "export" keyword was added to the standard, but since none of the "mainstream" compilers actually support "export", you are stuck with writing your template definitions in header files.
Every good solution is obvious once you've found it.
Seperating declaration and definition is not a bad idea at all, it is elementary to making C++ code maintainable.
Ho, Ho, i only mentioned that for templates this is a bad thing to do. For non-templates it is the only thing to do unless you want better performance then you inline the implementation
But it only seems to work with my constructors. My member functions (and I'm talking about my public interface) still doesn't like this workaround. The whole thing has me seriously vexed. I know I shouldn't expect my compiler to like the idea of separating the implementation, bu it just feels wrong to me.
#include "matrix.h"
// can't use "class Matrix;" because we're accessing the properties of Matrix within this file
template<class T>
class Vector3D<T>
{
// ...
Matrix CreateTranslationMatrix() // this is a template class so I can't put this in a .cpp
{
Matrix m;
// access internal properties of m here
return m;
}
// ...
}
#include "vector3d.h" // I can't define a prototype for Vector3D<int>
class Matrix
{
// ...
Vector3D<int> GetTranslation(); // the code for this is in Matrix.cpp
// ...
}
How could I do this? (I could make GetTranslation a static function inside Vector3Df but I do not want to do this.)
class matrix;
template< typename t>
class vector3d {
matrix CreateMatrix(void);
}
#include "matrix.h"
template< typename t>
matrix vector3d<t>::CreateMatrix(void) {
}
That gives me:
error C2065: 'T' : undeclared identifier
error C2955: 'MGF::Core::Vector3D' : use of class template requires template argument list
error C2509: 'CreateMatrix' : member function not declared in 'MGF::Core::Vector3D'