i need some help plz.. check the error in my pro

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
#include<iostream>
using namespace std;
typedef int errorcode;
#define success 0
#define underflow -1
#define overflow -2
template <class T>

class node{

public:T data;node * next;

	   node(){data=0;next=NULL;};
	   
	   node(T x){data =x;next=NULL;}

};

template <class T>

class Q{ 

protected:node * rear ;node * front;
		  int count;
public:Q();
	   ~Q();
	   errorcode append(T item);
	   errorcode retrieve(T & item);
	   errorcode serve();
	   bool isempty();
	   bool isfull(){return false;}
};

template <class T>
Q <T> ::Q(){
	cout<<"in constructer"<<endl;
	count=0;rear=front=NULL;
}

template <class T>
Q <T>::~Q(){
	node *p;
	while(front!=NULL){
		p=front;
		front=front ->next;
		delete p;
	}

template <class T>
errorcode Q <T>  ::append(T item){
	errorcode code = success;

	node * n;
	n=new node;
	n->data=item;
	n->next=NULL;

	if(isempty()){

		rear=front=n;
		count++;
	}

	else{
		rear->next=n
			rear=n;
		
		count++
	}
	return code;}


	template <class T>

	errorcode  Q <T> ::retrieve(T & item){
		errorcode code = success;

		if(isempty()){
			code = underflow;cout<<"empty"<<endl;}

		else{ item=front->data;}

		return code;
	}

template <class T>
	errorcode  Q <T> ::serve(){
		errorcode code =success;

		if(isempty()){code =underflow;cout<<"empty"<<endl;}

		else{
		node *p;
		p=front;
		front=front->next;
		delete p;
		count--;

		}
		return code;
	}

    template <class T>
	bool Q <T>::isempty(){
		if (front==NULL)return true;
		else return false;

	}

    template <class T>

	class exQ::public Q{

	public: int size();
			void clear();
			errorcode serve&retrieve(T & item);
			exQ();
	}

    template <class T>
		exQ <T>::exQ();
    template <class T>
		int exQ <T>::size(){
		return count;
	}

	
    template <class T>
		void exQ <T>::clear(){

		node *p;
		while(front!=NULL){
			p=front;
			front =front->next;
			delete p;}
		rear=NULL:
			count=0;
	}
 template <class T>
	 errorcode exQ <T>::serve&retrieve(T & item){
	 node *p;
	 errorcode code =success;
	 if(isempty()){code=underflow;cout<<"empty"<<endl;}
	 else{
		 item=front->data;
		 p=front;
		 front=front->next;
		 delete p;
		 count--;
	 }
	 return code;
 }
 


the error

--------------------Configuration: 5 - Win32 Debug--------------------
Compiling...
5.cpp
C:\5\5.cpp(160) : fatal error C1075: end of file found before the left brace '{' at 'C:\5\5.cpp(145)' was matched
Error executing cl.exe.

5.exe - 1 error(s), 0 warning(s)



wtz wrong !!!
1
2
3
4
5
6
7
Q <T>::~Q(){
	node *p;
	while(front!=NULL){
		p=front;
		front=front ->next;
		delete p;
	}


in line 48, the destructor of the Q class is missing a closing bracket.
hey Dacster13 ,,
i did wt u told me to do ,, but it get more complicated now,,,,


Compiling...
5.cpp
C:\5\5.cpp(117) : error C2955: 'Q' : use of class template requires template argument list
C:\5\5.cpp(37) : see declaration of 'Q'
C:\5\5.cpp(123) : see reference to class template instantiation 'exQ<T>' being compiled
C:\5\5.cpp(121) : error C2143: syntax error : missing ';' before '&'
C:\5\5.cpp(123) : see reference to class template instantiation 'exQ<T>' being compiled
C:\5\5.cpp(121) : error C2501: 'retrieve' : missing storage-class or type specifiers
C:\5\5.cpp(123) : see reference to class template instantiation 'exQ<T>' being compiled
C:\5\5.cpp(145) : error C2143: syntax error : missing ';' before '&'
C:\5\5.cpp(145) : error C2350: 'exQ<T>::serve' is not a static member
C:\5\5.cpp(145) : error C2059: syntax error : ';'
C:\5\5.cpp(145) : error C2061: syntax error : identifier 'T'
Error executing cl.exe.

5.exe - 7 error(s), 0 warning(s)



i think theres sth wrong with the inhertance coz it's of the kind template
I just noticed but your code has a lot of syntax errors in it.

line 23:
protected:node * rear ;node * front;

line 42:
node *p;

line 53-54:
1
2
node * n;
n=new node;


line 93:
node *p;

line 131:
node *p;

node must have an argument type since it's using a template so it needs to be like node<T> *rear and node<T> * front.



line 65:
rear->next=n

line 68:
count++

missing semi-colons.




line 112:
class exQ::public Q{

extra colon




line 116:
errorcode serve&retrieve(T & item);

line 140:
errorcode exQ <T>::serve&retrieve(T & item){

invalid method identifier, the & symbol is a special character and is not allowed to be used in identifiers.



line 118:
}

end of class declaration missing a semi-colon.




line 121:
exQ <T>::exQ();

class constructor missing a body.




line 136:
rear=NULL:

colon used to end statement instead of semi-colon.
Last edited on
ur amazing Dacster .. i got no error in the classes & i put <T> to the inheritance is it right ?!

class exQ:public Q<T>

& when i wrote the main to test my programme i got 102 errors !

1
2
3
4
5
int x;
Q <int> r;
r.append(2);
r.append(7);
r.retrieve(x);



my programme
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
166
167
168
169
170

#include<iostream>
using namespace std;
typedef int errorcode;
#define success 0
#define underflow -1
#define overflow -2
template <class T>

class node{

public:T data;node<T> * next;

	   node(){data=0;next=NULL;};
	   
	   node(T x){data =x;next=NULL;}

};

template <class T>

class Q{ 

protected:node<T> * rear ;node <T>* front;
		  int count;
public:Q();
	   ~Q();
	   errorcode append(T item);
	   errorcode retrieve(T & item);
	   errorcode serve();
	   bool isempty();
	   bool isfull(){return false;}
};

template <class T>
Q <T> ::Q(){
	cout<<"in constructer"<<endl;
	count=0;rear=front=NULL;
}

template <class T>
Q <T>::~Q(){
	node *p;
	while(front!=NULL){
		p=front;
		front=front ->next;
		delete p;}
	}

template <class T>
errorcode Q <T>  ::append(T item){
	errorcode code = success;

	node<T> * n;
	n=new <T>node;
	n->data=item;
	n->next=NULL;

	if(isempty()){

		rear=front=n;
		count++;
	}

	else{
		rear->next=n;
			rear=n;
		
		count++;
	}
	return code;}


	template <class T>

	errorcode  Q <T> ::retrieve(T & item){
		errorcode code = success;

		if(isempty()){
			code = underflow;cout<<"empty"<<endl;}

		else{ item=front->data;}

		return code;
	}

template <class T>
	errorcode  Q <T> ::serve(){
		errorcode code =success;

		if(isempty()){code =underflow;cout<<"empty"<<endl;}

		else{
		node<T> *p;
		p=front;
		front=front->next;
		delete p;
		count--;

		}
		return code;
	}

    template <class T>
	bool Q <T>::isempty(){
		if (front==NULL)return true;
		else return false;

	}

    


	template <class T>

	class exQ:public Q<T> {

	public: int size();
			void clear();
			errorcode serveandretrieve(T &item);
			exQ();
	};

    template <class T>
		exQ <T>::exQ(){cout<<"created by defualt"<<endl};
    template <class T>
		int exQ <T>::size(){
		return count;
	}

	
    template <class T>
		void exQ <T>::clear(){

		node <T>*p;
		while(front!=NULL){
			p=front;
			front =front->next;
			delete p;}
		rear=NULL;
			count=0;
	}
 template <class T>

	 errorcode exQ <T>::serveandretrieve(T &item){
	 node *p;
	 errorcode code =success;
	 if(isempty()){code=underflow;cout<<"empty"<<endl;}
	 else{
		 item=front->data;
		 p=front;
		 front=front->next;
		 delete p;
		 count--;
	 }
	 return code;
 }
 
 int main(){

/*int x;
Q <int> r;
r.append(2);
r.append(7);
r.retrieve(x);*/


	 return 0;
 }
Last edited on
The two lingering errors I see are here:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
template <class T>
Q <T>::~Q(){
	node<T> *p;  // must be node<T>, not node.  Remember, node is not a class.  node<T> is the class.
	while(front!=NULL){
		p=front;
		front=front ->next;
		delete p;}
	}

template <class T>
errorcode Q <T>  ::append(T item){
	errorcode code = success;

	node<T> * n;
	n=new node<T>;  // <-  node<T>, not <T>node.
	n->data=item;
thanx Disch .. ur the best ever :))
it works ..
Topic archived. No new replies allowed.