As I jump deeper into C++ I come into increasingly strange errors. Templates have been one of them. In my test programs (with simple templates) everything was fine, but I've taken some stuff out of my C++ book for Binary Tree's as a class, and class extentions, and I can't get it all to work correctly.
I've compiled the code into a library, and I also tried just adding the files to the test project I'm working on, but I keep getting these linking errors:
main.o: In function `ZN3BSTIiEC1Ev':
C:/programming projects/binary_tree_lib/test/main.cpp:(.text$_ZN3BSTIiED1Ev[BST<int>::~BST()]+0xd): undefined reference to `BTree<int>::~BTree()'
C:/programming projects/binary_tree_lib/test/main.cpp:(.text$_ZN3BSTIiEC1Ev[BST<int>::BST()]+0xd): undefined reference to `BTree<int>::BTree()'
Now, it all compiled fine, but when I try this in some function:
It throws those errors. I've tried with several standard data types, all with the same errors. BST is a derived class from BTree. The constructors and destructors it is referencing to are thus:
Both are declared in the class definition, and both are present in the code. Again, it compiled correctly, these are linking errors.
I'm not really sure where to go from here. Any help? Thanks :)
I've compiled the code into a library, and I also tried just adding the files to the test project I'm working on, but I keep getting these linking errors:
main.o: In function `ZN3BSTIiEC1Ev':
C:/programming projects/binary_tree_lib/test/main.cpp:(.text$_ZN3BSTIiED1Ev[BST<int>::~BST()]+0xd): undefined reference to `BTree<int>::~BTree()'
C:/programming projects/binary_tree_lib/test/main.cpp:(.text$_ZN3BSTIiEC1Ev[BST<int>::BST()]+0xd): undefined reference to `BTree<int>::BTree()'
Now, it all compiled fine, but when I try this in some function:
BST<int> tree;
It throws those errors. I've tried with several standard data types, all with the same errors. BST is a derived class from BTree. The constructors and destructors it is referencing to are thus:
template<class elemType>
BTree<elemType>::BTree()
{
root = NULL;
} // end default constructor
template<class elemType>
BTree<elemType>::~BTree()
{
Destroy(root);
} // end destructor
Both are declared in the class definition, and both are present in the code. Again, it compiled correctly, these are linking errors.
I'm not really sure where to go from here. Any help? Thanks :)