Stack template has some logical error for implementing binary tree
<p>i have a template of stack and a template of TreeNode (Binary Tree). Following is the code of two classes (stack and TreeNode). I succesfully inserted data into tree by using insert() function but there is a problem while retrieving it back using stack. Following are the compile time errors: </p>

<p><strong>Error 1   error C2143: syntax error : missing ';' before '*'  c:\users\computer house\desktop\tree 1\tree 1\source.cpp    8   1   Tree 1</strong></p>

<p><strong>Error 2   error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   c:\users\computer house\desktop\tree 1\tree 1\source.cpp    8   1   Tree 1</strong></p>

<pre><code>#include&lt;iostream&gt;
#include&lt;stdlib.h&gt;
using namespace std;

template&lt;class T&gt;
class Stack{
private:
    TreeNode&lt;T&gt; *headNode, *pastCurrentNode;

public:
    Stack(){
        headNode = new TreeNode&lt;T&gt;;
        headNode=NULL;
    }

    void push(T x){
        TreeNode&lt;T&gt;* newNode = new TreeNode&lt;T&gt;;
        newNode-&gt;set(x);

        if(headNode != NULL){
            newNode-&gt;setNext(headNode);
            pastCurrentNode=headNode;
            headNode=newNode;
        }
        else{
            headNode=newNode;
            pastCurrentNode=headNode;
        }
    }

    T pop(){
        TreeNode&lt;T&gt;* p = new TreeNode&lt;T&gt;;
        p = headNode;
        headNode = pastCurrentNode;
        T x = p-&gt;get();
        delete p;
        return x;
    }

    T top(){return headNode-&gt;get();}

    bool isEmpty(){return (headNode == NULL);}
};

template&lt;class T&gt;
class TreeNode{
private:
    TreeNode* right, *left;
    T* object;


public:
    TreeNode(){
        this-&gt;left = this-&gt;right = NULL;
        object = NULL;
    }

    TreeNode(T* object){
        this-&gt;object  = object;
        this-&gt;left = this-&gt;right = NULL;
    }

    T* getInfo(){
        return this-&gt;object;
    }

    void setInfo(T* object){
        this-&gt;object = object;
    }

    TreeNode* getLeft(){return this-&gt;left;}
    void setLeft(TreeNode* left){this-&gt;left = left;}
    TreeNode* getRight(){return this-&gt;right;}
    void setRight(TreeNode* right){this-&gt;right = right;}

    int isLeaf(){
        if(this-&gt;left==NULL &amp;&amp; this-&gt;right == NULL){
            return 1;
        }
        return 0;
    }

};


void insert(TreeNode&lt;int&gt;* root, int* info){
    TreeNode&lt;int&gt;* newNode = new TreeNode&lt;int&gt;(info);
    TreeNode&lt;int&gt;*p, *q;

    p = q = root;

    while(*info != *p-&gt;getInfo() &amp;&amp; q != NULL)
    {
        p = q;

        if(*info &lt; *p-&gt;getInfo())
            q = p-&gt;getLeft();
        else 
            q = p-&gt;getRight();

    }

    if(*info == *p-&gt;getInfo()){
        cout&lt;&lt;"Error: Duplication: "&lt;&lt;*info&lt;&lt;endl;
        delete newNode;
    }
    else if(*info &lt; *p-&gt;getInfo()){
        p-&gt;setLeft(newNode);
    }
    else{
        p-&gt;setRight(newNode);
    }
}



void sInOrder(TreeNode&lt;int&gt;* root){
    Stack&lt; TreeNode&lt;int&gt;* &gt; stack;
    TreeNode&lt;int&gt;* p;

    p=root;

    do{
        while(p != NULL){
            stack.push(p);
            p = p-&gt;getLeft();
        }
        //At this point left tree is empty

        if(! stack.isEmpty()){
            p = stack.pop();
            cout&lt;&lt;*p-&gt;getInfo()&lt;&lt;" ";
            //go back and traverse right subtree
            p = p-&gt;getRight();
        }
    }
    while(!stack.isEmpty() || p!=NULL);

}

int main(){

    int x[]={14,15,4,9,7,18,3,5,16,4,20,17,9,14,5,-1};
    TreeNode&lt;int&gt;* root = new TreeNode&lt;int&gt;;

    root-&gt;setInfo(&amp;x[0]);

    for(int i=1; x[i]&gt;0; i++){
        insert(root, &amp;x[i]);
    }

    cout&lt;&lt;"\nStacked In Order: "; sInOrder(root);
    cout&lt;&lt;endl;


    system("pause");
}
</code></pre>