I'm asking your help because I'm using templates and it seems like I misunderstood something.
Here's my code :
arbre.h
template<typename T>
class Arbre;
template<typename T>
class Noeud
{
friend class Arbre<T>;
public :
Noeud();
~Noeud();
T get_info()const;
private :
T info;
Noeud<T> *fg, *fd;
};
template<typename T>
class Arbre
{
public :
//Constructors-------------------------------------------------------------
Arbre();
/*
other function definitions
*/
}
arbre.tpp
#include "arbre.h"
template <typename T>
Noeud<T>::Noeud(){
fg = fd = 0;
}
template <typename T>
Noeud<T>::~Noeud(){
}
template <typename T>
T Noeud<T>::get_info()const{
return info;
}
template <typename T>
Arbre<T>::Arbre(){
racine = 0;
}
/*
other function implementations...
*/
The main.cpp includes "arbre.h" and creates an object like so :
Arbre<int> a;
So following this article on explicit instantiation : http://www.cplusplus.com/forum/articles/14272/
I added those 2 lines at the end of arbre.tpp :
template class Noeud<int>;
template class Arbre<int>;
So that the linker can compile the code for the int version of my object in arbre.o and so I could keep the implementation (arbre.tpp) apart from the header (arbre.h). My code worked with implicit instantiation (arbre.tpp included at the end of header.h) but I wanted to keep them apart.
I wonder why does the linking fail :
g++ -o main.o -c main.cpp -Wall -g -std=c++11
g++ -o arbre.o -c arbre.tpp -Wall -g -std=c++11
g++: warning: arbre.tpp: linker input file unused because linking not done
g++ -o arbre.out main.o arbre.o
g++: error: arbre.o: No such file or directory
Makefile:9: recipe for target 'arbre.out' failed
make: *** [arbre.out] Error 1
Do you have any idea ? I'm doing the same thing as in the article I linked aren't I ?
Thanks in advance.