Unsolvable error

hey everyone.
so i've been struggling with this out of space error for the last 6 hours can any one heeelp please ...

main.cpp
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
  #include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include "class.h"
#include "class.cpp"

using namespace std;


int main(){
	lList list;
	Node* rat = new Node;
	int input;
	do {
		system("cls");
		list.Show();
		cout << "\n Make A Choice Sir : ...\n";
		cout << "|-1-|Add A New Manager .\t|-2-|Add A New Vehicle .\n";
		cout << "|-3-|   Delete Manager .\t|-4-|Delete Vehicle .\n";
		cout << "|-5-|Assign Vehicle To Manager .|-6-|UnAssign Vehicle From Manager .\n";
		cout << "|-7-|Make The List Empty .\t|-0-|Exit .";
		cout << "\n Your Choice Is ->>>  " ;
		list.checkInputNum(input);
		switch (input){
			case 1:
				list.addNode('m');
				break;
			case 2:
				list.addNode('v');
				break;
			case 3:
				list.deleteNode('m');
				break;
			case 4:
				list.deleteNode('v');
				break;
			case 5:
				list.assignVehicle("assign");
				break;
			case 6:
				list.assignVehicle("unassign");
				break;
			case 7:
				list.makeEmpty();
				break;
		}
	}while(input != 0);
}

class.h
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



#ifndef CLASS_H
#define CLASS_H
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>

using namespace std;

struct Node{
		string name;
		Node *next;
	};
struct NodeVeh{
	string name,manager;
	int price,year;
	NodeVeh *next;
};


class lList{
	Node *head;
	NodeVeh *headVeh;
public:
lList();

void checkInputStr(string& name);
void checkInputNum(int &num);
void Show();
void addNode(char choice);
void deleteNode(char choice);
bool validateManagerVehicle(Node* &man,NodeVeh* &veh,string strman,string strveh);
void assignVehicle(string order);
void makeEmpty();

~lList();
};
#endif 

class.cpp
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
 #include <iostream>
#include <fstream>
#include <vector>
#include <cstdlib>
#include "class.h"

using namespace std;

lList::lList() : head(NULL) , headVeh(NULL) {}

void lList::checkInputStr(string& name){
	char c;
	cin>> name;
	c = name.at(0);
	c =tolower(c);
	if (! (c >= 'a' || c <= 'z' ) ){
	cout << "\nplease make sure the first digit is a letter >> ";
	return checkInputStr(name);
	}
}

void lList::checkInputNum(int &num){
		if (!(cin >> num)){
			cout << "\nType In A Valid Number Please -->> ";
			cin.clear();
			cin.ignore(2000,'\n');
			return checkInputNum(num);
		}

}

void lList::Show(){
		Node *te = head;
		cout << " \n  Managers Are || ";
		while (te != NULL)
		{
			cout<< " " << te->name << "|| ";
			te = te->next;
		}
		cout << "\n*****************************************************************************"<< endl;
		NodeVeh *tee = headVeh;
		cout << "  Vehicle\t||\tPrice\t||\tYear\t||\tManager Of Vehicle \n";
		while (tee != NULL)
		{
			cout << " " << tee->name << " \t\t||\t" << tee->price << "\t||\t" << tee->year << "\t||\t" << tee->manager << endl;
			tee = tee->next;
		}
		cout << "\n*****************************************************************************"<< endl;
}
void lList::addNode(char choice){
	if (choice == 'm'){
	    Node *p = new Node;
		p->next = NULL;
		cout << "\nEnter Name Of Manager Please : ";
		checkInputStr(p->name);
		if (head == NULL)
			head = p;
		else{
			p->next = head;
			head = p;
		}
	}
	if (choice == 'v'){
		NodeVeh *p = new NodeVeh;
		p->next = NULL;
		p->manager = "NULL";
		cout << "\nEnter Name Of Vehicle Please : ";
		checkInputStr(p->name);
		cout << "\nEnter Price Of Vehicle Please : ";
		checkInputNum(p->price);
		cout << "\nEnter Year Of Vehicle Please : ";
		checkInputNum(p->year);
		if (headVeh == NULL)
			headVeh = p;
		else{
			p->next = headVeh;
			headVeh = p;
		}
	}

}

void lList::deleteNode(char choice){
		string str;
		if (choice == 'm'){
		Node *ptr = new Node;Node *follow;
		ptr = head;
		follow = ptr;
		cout << "\nEnter Name OF Manager To Delete : " ;
		checkInputStr(str);
		while(ptr != NULL){
			if (head->name == str ){
				head = head->next;
					NodeVeh* search = headVeh;
					while (search != NULL){
						if(search->manager == str)
							search->manager = "NULL";
						if(search == NULL)
							break;
						search = search->next;
					}
				delete ptr;
				break;
			}
			if (ptr->name == str){
				follow->next = ptr->next;
					NodeVeh* search = headVeh;
					while (search != NULL){
						if(search->manager == str)
							search->manager = "NULL";
						if(search == NULL)
							break;
						search = search->next;
					}
				delete ptr;
				break;
			}
			follow = ptr;
			ptr = ptr->next;
		}
	}
	if (choice == 'v'){
		NodeVeh *p = new NodeVeh;NodeVeh *foll;
		p = headVeh;
		foll = p;
		cout << "\nEnter Name OF Vehicle To Delete : " ;
		checkInputStr(str);
		while(p != NULL){
			if (headVeh->name == str ){
				headVeh = headVeh->next;
				delete p;
				break;
			}
			if (p->name == str){
				foll->next = p->next;
				delete p;
				break;
			}
			foll = p;
			p = p->next;
		}
	}
}

bool lList::validateManagerVehicle(Node* &man,NodeVeh* &veh,string strman,string strveh){
	man = head;veh = headVeh;
	while (man != NULL){
		if (man->name == strman)
			break;
		if (man == NULL){
			cout << "\nThis Manager Isn't In The List ... " ;
			return false;
		}
		man = man->next;
	}
	while (veh != NULL){
		if (veh->name == strveh)
			return true;
		if (veh == NULL){
			cout << "\nThis Vehicle Isn't In The List ...";
			return false;
		}
		veh = veh->next;
	}
}

void lList::assignVehicle(string order){
	Node* man;NodeVeh* veh = headVeh;
	string manName,vehName;
	if (order == "assign"){
		cout << "\n Enter Managers Name You Wish To Assign A Vehicle To : ";
		checkInputStr(manName);
		cout << "\n Enter Vehicle Name You Wish To Assign A Manager To : ";
		checkInputStr(vehName);
		if (validateManagerVehicle(man,veh,manName,vehName))
			veh->manager = manName;
		else
			cout << "\nInformation Given Is Not Valid .";
	}
	if (order == "unassign"){
		cout << "\n Enter Vehicle Name You Wish To UnAssign A Manager From : ";
		checkInputStr(vehName);
		while (veh != NULL){
			if (veh->name == vehName){
				veh->manager = "NULL";
				break;
			}
			if (veh == NULL){
				cout << "\nThis Vehicle Isn't In The List ... ";
				break;
			}
			veh = veh->next;
		}
	}
}

void lList::makeEmpty(){
	Node *p = head;
	while (p != NULL){
		head = head->next;
		delete p;
		p = head;
		if (p == NULL){
			head = NULL;
			break;
		}
	}
	NodeVeh *d = headVeh;
	while (d != NULL){
		headVeh = headVeh->next;
		delete d;
		d = headVeh;
		if (d == NULL){
			headVeh = NULL;
			break;
		}
	}
}

lList::~lList(){
		makeEmpty();
	}


All of them are in one folder
and this is the error
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
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:6:0:
C:\Users\TOSHIBA\Desktop\work\class.cpp:145:6: error: redefinition of 'bool lList::validateManagerVehicle(Node*&, NodeVeh*&, std::string, std::string)'
 bool lList::validateManagerVehicle(Node* &man,NodeVeh* &veh,string strman,string strveh){
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:5:0:
C:\Users\TOSHIBA\Desktop\work\class.h:35:6: error: 'bool lList::validateManagerVehicle(Node*&, NodeVeh*&, std::string, std::string)' previously defined here
 bool validateManagerVehicle(Node* &man,NodeVeh* &veh,string strman,string strveh){};
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:6:0:
C:\Users\TOSHIBA\Desktop\work\class.cpp:167:6: error: redefinition of 'void lList::assignVehicle(std::string)'
 void lList::assignVehicle(string order){
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:5:0:
C:\Users\TOSHIBA\Desktop\work\class.h:36:6: error: 'void lList::assignVehicle(std::string)' previously defined here
 void assignVehicle(string order){};
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:6:0:
C:\Users\TOSHIBA\Desktop\work\class.cpp:197:6: error: redefinition of 'void lList::makeEmpty()'
 void lList::makeEmpty(){
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:5:0:
C:\Users\TOSHIBA\Desktop\work\class.h:37:6: error: 'void lList::makeEmpty()' previously defined here
 void makeEmpty(){};
      ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:6:0:
C:\Users\TOSHIBA\Desktop\work\class.cpp:220:1: error: redefinition of 'lList::~lList()'
 lList::~lList(){
 ^
In file included from C:\Users\TOSHIBA\Desktop\work\main.cpp:5:0:
C:\Users\TOSHIBA\Desktop\work\class.h:39:1: error: 'lList::~lList()' previously defined here
 ~lList(){};
 ^

help please it's for an assignment submission tomorrow.

THANKS
You're not supposed to include .cpp files.
that was one of the suggested solutions but the problem remains with or without the #include "class.cpp" file
If I comment out this line #include "class.cpp" in main.cpp, your code compiles for me.
thanks for making the time to answer and try my code wildblue .
so your saying it might be a compiler issue ??
and can you show me how do you issue the command to compiler to compile like "g++ ??" ??
Last edited on
No, neither wildblue nor helios were saying that this is a compiler issue. This is clearly a function redefinition issue.

What the macro "#include" does is copies + paste the contents of the source file you designate, into the destination file that it was invoked from, at the position that it is used. So then when you link to a source code file that you have also included, your linker sees the definition for a function with the exact same signature twice in the look-up table. This leads to a potential ambiguity error with overload resolution. Even though you and I both know that it is the exact same function, from the exact same source file, defined in exactly the same way across both instance, your linker does not care and won't even bother to check for that scenario. They each have the same name-decoration and this could potentially confuse the compiler and\or the run-time provider and that is all that it cares about.

Always try to remember that computers are incredibly stupid devices. You HAVE to hold their hand in everything that they do or else they will happily face plant while trying to perform even the simplest task.
Last edited on
how do you issue the command to compiler

I prefer GNU make (or better yet cmake/qmake/autotools), but in such a tiny project:
g++ -std=c++11 -Wall -Wextra -pedantic -g main.cpp class.cpp
Topic archived. No new replies allowed.