What is the mistake?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
template <class T>
class stack//Stack Class
{
      public:
             T data[sos];
             int tos;
             stack()
             {
                    tos=-1;
             }
             
             bool isEmpty()
             {
                  return (tos<0);
             }
             
             
             bool isFull()
             {
                  return (tos==sos);
             }
             
             bool push(T value)
             {
                  if(!isFull())
                  {
                            data[++tos]=value;    
                            return true;
                  }
                  else
                            return false;
             }
             
             T pop(T value)
             {
                 if(!isEmpty())
                 {
                              value=data[tos--]; 
                              return value;
                 }
                 else
                              return -999;
             }
             //friend class tree;
};


This is my stack classs and below is my class tree.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class tree//Tree
{
      public:
      bst *head;//Root Node
     // queue objQ;
      stack s;//Stack for implementing postOrder1 without recursion,
             tree()
             {
                   head=0;
             }   
             void insert(int num)//Insertion to make bst properly working.
             {
                  
                  bst *temp=head;
                  bst *prev=head;
                  bst *p=new bst(num);
                  while(temp)
                  {
                             prev=temp;
                             if(temp->myData>p->myData)
                             {
                                                       temp=temp->left;
                             }
                             else
                                                       temp=temp->right;
                             
                  }
                  if(head==NULL)
                  {
                           head=p;
                  }
                  else
                  {
                           if(prev->myData>p->myData)
                           prev->left=p;
                           else
                           prev->right=p;   
                  }
             }
             
};


my program is giving error

"stack does not name a type."
closed account (zb0S216C)
"stack" is a template-class and needs template arguments when you create an instance of it. In your "tree" class, you declare a "stack" but do not provide the template parameters.

1
2
3
4
class tree
{
      public:
      stack<int> s; // Missing the parameters here. 

If that does not resolve your problem, ensure that "tree" knows about "stack" by including the header in which "stack" is defined into "tree"'s header.

Wazzak
The couple things I see:
Template line 5, where does sos come from?
class tree line 4, where is bst defined?


Topic archived. No new replies allowed.