I have a generic class which in I also have a struct. Like this:
template <class T> class Octree
{
public:
struct node
{
typename T value;
node *child[8];
};
Octree();
template <class T> Octree();
~Octree();
void clear(T t);
node* root;
};
the .cpp file :
template <class T>
Octree<T>::Octree()
{
root = new node;
root->value = 0;
for (int i = 0; i < 8; i++)
root->child[i] = 0;
}
template <class T>
Octree<T>::~Octree()
{
clear(root);
}
and the main:
using namespace std;
int main() {
Octree <int> fasz;
Octree <char> fasz2;
return 0;
}
I've just created an object of my tree and I got this error:
Error LNK2019 unresolved external symbol "public: __thiscall Octree::Octree(void)" (??0?$Octree@H@@QAE@XZ) referenced in function _main Zz c:\Users....Source.obj
I have tried to write the template declaration in a header file, then implement the class in an implementation file (for example .cpp), and include this implementation file at the end of the header but then I've got an error:
Error C2995 'Octree::Octree(void)': function template has already been defined
I have seen this link question but it's not what I need.
Have you any idea what the problem is?