I am having trouble with friend functions
I have the following classes to implement building an expression tree. I have a function that I am having trouble placing: the buildTree function in class Tree. I am getting an undefined reference error. How can I declare it so that I may call the function in main but still access what i need to access from the classes?
Code:
template<class object>
struct Node
{
object info;
Node *next;
Node<object>():info(0), next(NULL) {}
Node<object>(const object &element, Node *n = NULL):
info(element), next(n){}
};
template<class object>
class Stack
{
public:
Stack();
~Stack();
void makestackempty();
bool stackEmpty() const;
void push(object &item);
void pop (object &item);
void printStack() const;
private:
Node<object> *top;
};
template<class object>
struct TreeNode
{
object info;
TreeNode *right;
TreeNode *left;
TreeNode()
{}
};
template<class object>
class Tree
{
private:
TreeNode<object> *root;
public:
Tree();
~Tree();
Tree(const Tree<object> &rhs); // copy
void operator=(const Tree<object> &rhs);
void copyconst(TreeNode<object> *orig, TreeNode<object> *&rhs);
void makeEmpty(TreeNode<object> *&tree);
bool isEmpty()const;
friend void buildTree(TreeNode<object> *&tree);
void printTree(TreeNode<object> *&tree)const;
};
In main i currently have:
Code:
Tree<string> T;
cout << "Enter postfix expression to convert:" << endl;
buildTree(T);
Any insight would be appreciated.