I m really sorry if this question's origin reside in my profound lack of understanding of the template concept itself.
I had defined the following class.
#include <iostream>
template <typename T>
class T3B_data{
public:
T3B_data<T>();
~T3B_data<T>();
void fromText(std::istream& is);
void fromText(const std::string& textPath);
void fromBinary(std::istream& is);
std::ostream & toText(std::ostream& oStream)const;
std::ostream & toBinary(std::ostream& oStream);
friend inline std::ostream& operator << (std::ostream & oStream,const T3B_data<T> & data){
return data.toText(oStream);
}
private:
T * mObj;
};
In order to make a simple template test i tried the following main in order to instantiate it
#include "T3B_data.h"
int main(void){
T3B_data<int> * myData = new T3B_data<int>();
return 0;
}
i don t get why did i had to instanciate the template explicitly by adding:
template class T3B_data<int>;
at the end of the header file for the compiler to find the class constructor.
Note :
I m fully aware that appending the line actually force a whole new class generation. i just don t get why the code in the main did not actually force template instanciation at compiler level.
Note 2:
I m quite sure i m making something wrong, because when using STL containers i do not need to instanciate it whenever i use it with a self defined type like :
struct myStruct{
int a;
std::string;
};
std::vector<myStruct> a;
Thanks in advance to any people sharing interest in this question.
EDIT :
Something must be utterly wrong in my implementation, as i move my header file into my main and stubbed implementation using {} at end of declaration. and everything compiles fine without the template class T3B_data; declaration.
Question ending up being a duplicate to separating constructor implementation with template from header file