@whiteflags Yes. I remember posting this code in frustration, I've fixed the type long ago when I had a brief moment of clarity. Haha
So, It still doesnt compile for me. Maybe my compiler doesn't like it.
Here is the only error I am getting:
In function `main':
302hw4code2.cpp.text+0xae): undefined reference to `void expTree<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(Tree<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >*&)'
collect2: ld returned 1 exit status
the only piece of code that's relevant I have already posted. but for this error, these are the classes I currently have:
Code:
#include<iostream>
#include<string>
using namespace std;
template<class object> class Tree;
template<class object> void expTree(Tree<object> *&T);
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 expTree(Tree<object> *&T){
buildTree(T.root);
}
void buildTree(TreeNode<object> *&tree);
void printTree(TreeNode<object> *&tree)const;
};
and the main, even with little tweaks.
Code:
int main()
{
Tree<std::string> *T;
std::cout << "Enter postfix expression to convert:" << std::endl;
expTree(T);
return 0;
}
My solution for now is i've written a new code with only one struct, and no templates. haha. It compiles. Sad code but ive gotten no stubborn errors. Working code is better than noncompiling code!