I had a problem creating a class object from a template class, in which I need a constructor, which should also be a template and take a parameter when creating the object. However, when I try to create an object, I get an error message indicating that I am referring to something that does not exist.
Here is my code:
using namespace std; #include <cstdlib> template <class Node_Type> class BinaryTree { public: BinaryTree(Node_Type); BinaryTree(Node_Type, Node_Type); BinaryTree(Node_Type, Node_Type, Node_Type); bool isEmpty(); Node_Type info(); Node_Type inOrder(); Node_Type preOrder(); Node_Type postOrder(); private: struct Tree_Node { Node_Type Node_Info; BinaryTree<Node_Type> *left; BinaryTree<Node_Type> *right; }; Tree_Node *root; }; #endif
and my .cpp:
template <class Node_Type> BinaryTree<Node_Type>::BinaryTree(Node_Type rootNode) { root = rootNode; root->left = NULL; root->right = NULL; }
There's more to .cpp, but these are just other function members that don't matter. My constructor shown above is something that I cannot work with.
Basically, I'm trying to declare my object with a call:
BinaryTree<char> node('a');
but when I try this, I get an error message:
undefined reference to `BinaryTree<char>::BinaryTree(char)'
I have been trying to figure this out for two days now. I have searched for every topic that I can think of, and read countless examples in Qaru and other sources without any help. Can someone explain what my problem is? I know how to make my project, and I would finish if the syntax werenβt so funny in C ++. Thanks in advance!
source share