Hi all,
I have a "template.h" file with a class template declaration, and I have "template.cpp" file with the definition of this class template.
It turns out that I have the following compilation error:
undefined reference to `vec<double>::foo()'
After googling, I found a post assuring that the class template definition MUST go along in the header file. They cannot reside in two separate files
Is this for real??
Below are the two files:
//===============template.h=================
template<class T>
class vec{
public:
vec( ){ dim = 0; }
void foo(void);
protected:
int dim ;
};
//===============template.cpp================
#include<iostream.h>
using namespace std;
#include "template.h"
template<class T>
void vec<T>::foo(void){
cout <<"foo function\n";
}
//===========================================
I have a "template.h" file with a class template declaration, and I have "template.cpp" file with the definition of this class template.
It turns out that I have the following compilation error:
undefined reference to `vec<double>::foo()'
After googling, I found a post assuring that the class template definition MUST go along in the header file. They cannot reside in two separate files
Is this for real??
Below are the two files:
//===============template.h=================
template<class T>
class vec{
public:
vec( ){ dim = 0; }
void foo(void);
protected:
int dim ;
};
//===============template.cpp================
#include<iostream.h>
using namespace std;
#include "template.h"
template<class T>
void vec<T>::foo(void){
cout <<"foo function\n";
}
//===========================================