missing type specifier error

There is an error in this part of code i cant figure out why and what is the fix for it and it says "missing type specifier - int assumed. Note: C++ does not support default-int":
1
2
3
4
5
  template<class ItemType> class Stack
{
private:
	NodeType<ItemType> *topPtr, *tailPtr, *temp;
	int stackLength;


Here is the entire code:
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  #include <iostream>
using namespace std;

template<class ItemType> class Stack
{
private:
	NodeType<ItemType> *topPtr, *tailPtr, *temp;
	int stackLength;
	int top;
public:
	Stack()
	{
		top = -1
	};

	void MakeEmpty()
	{
		top = -1
	};

	bool IsEmpty()
	{
		return (top == -1);
	};

	bool IsFull()
	{
		return (top == 5)
	};


	int length()
	{
		return stackLength
	};

	void Print()
	{
		for (; topPtr; topPtr = topPtr->next)
		{
			cout << temp->value << endl;
			temp = temp->next;
		}
	};

	void Push(ItemType x)
	{
		if (IsFull())
		{
			cout << "Stack is full";
			return;
		}
		if (topPtr == NULL)
		{
			topPtr = new NodeType<ItemType>;
			topPtr->info = x;
			tailPtr = topPtr;
			top++;
			length++;
		}
		else
		{
			temp = new NodeType<ItemType>;
			temp->info = x;
			temp->next = NULL;
			tail->next = temp;
			tail = tail->next;
			top++;
			length++;
		}
	};

	void Pop(ItemType &x)
	{
		NodeType<ItemType> *p1=topPtr, *temp1;
		if (top == -1)
		{
			cout << "stack is empty";
				return;
		}
		
		if (x == topPtr->info)
		{
			temp1 = p1;
			topPtr = topPtr->next;
		}

		else
		{
			while (!(x == p1->next)->info)
			{
				p1 = p1->next;
			}
			temp = p1->next;
			p1->next = (p1->next)->next;
		}

		delete temp1;
	};
	
	//~Stack();  // Destructor:  memory for nodes needs to be deallocated
};

template<class ItemType>
struct NodeType
{
	ItemType info;
	NodeType* next;
};





int main()
{

	Stack <int> IntStack;
	int x;
	IntStack.Pop(x);
	IntStack.Push(11);
	IntStack.Push(22);
	cout << "int length 1 = " << IntStack.length() << endl;
	IntStack.Pop(x);
	IntStack.Push(33);
	cout << "int length 2 = " << IntStack.length() << endl;
	cout << "The int stack contains : " << endl;
	IntStack.Print();
	IntStack.Push(44);
	IntStack.Push(55);
	IntStack.Push(66);
	if (IntStack.IsFull() == false)
		cout << "The int stack is not full !" << endl;
	else
		cout << "The int stack is full !" << endl;
	Stack <int> IntStack2(IntStack);
	cout << "The int stack2 contains : " << endl;
	IntStack2.Print();
	IntStack2.MakeEmpty();
	cout << "The int stack3 contains : " << endl;
	IntStack2.Print();


	Stack <float> FloatStack;
	float y;
	FloatStack.Pop(y);
	FloatStack.Push(7.1);
	cout << "float length 1 = " << FloatStack.length() << endl;
	FloatStack.Push(2.3);
	FloatStack.Push(3.1);
	cout << "float length 2 = " << FloatStack.length() << endl;
	FloatStack.Pop(y);
	cout << "The float stack contains : " << endl;
	FloatStack.Print();
	Stack <float> FloatStack2 = FloatStack;
	cout << "The float stack 2 contains:  " << endl;
	FloatStack2.Print();
	FloatStack.MakeEmpty();
	cout << "The float stack 3 contains:  " << endl;
	FloatStack2.Print();


	system("PAUSE");
	return 0;
}
You need to define NodeType before you define Stack.
Gotcha, thanks alot
Last edited on
Simply move lines 104-109 to before line 4.

Lines 13,18,28,34: missing ;

Line 48: value is not a member of NodeType (temp).

Line 59, 69: length is a function. You can't increment it.

Lines 66-67; tail is undefined. Did you mean tailptr?

There are more errors, but I stopped there.


Topic archived. No new replies allowed.