Base Class Undefined

My compiler error is 'department' base class undefined.

Very confused because all I wan't to do is just inherit.

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
223
224
225
226
227
228
229
230
231
232
233
234
#include <iostream>
#include <string>
#include "Department.h"
#include "Staff.h"


using namespace std;

// Function prototypes
void menu();
void subM();
void subS();
void subP();

//Menu Display functions.
void menu() {
	cout << "\nMain Menu:";
	cout << "\n1. Department menu" << endl;
	cout << "\n2. Staff menu" << endl;
	cout << "\n3. Patient menu" << endl;
	cout << "\n4. Exit" << endl;

	cout << "\nEnter a choice (1 - 4): ";
}

//Department Menu
void subM() {
	cout << "\nDepartment Menu:";
	cout << "\n1. List all" << endl;
	cout << "\n2. Add one" << endl;
	cout << "\n3. Search one" << endl;
	cout << "\n4. Edit one" << endl;
	cout << "\n5. Delete one" << endl;
	cout << "\n6. Return to main menu" << endl;

	cout << "\nEnter a choice (1 - 4): ";
}
//Staff Menu
void subS() {
	cout << "\nStaff Menu:";
	cout << "\n1. List all" << endl;
	cout << "\n2. Add one" << endl;
	cout << "\n3. Search one" << endl;
	cout << "\n4. Edit one" << endl;
	cout << "\n5. Delete one" << endl;
	cout << "\n6. Return to main menu" << endl;

	cout << "\nEnter a choice (1 - 4): ";
}
//Patient Menu
void subP() {
	cout << "\nPatient Menu:";
	cout << "\n1. List all" << endl;
	cout << "\n2. Add one" << endl;
	cout << "\n3. Search one" << endl;
	cout << "\n4. Edit one" << endl;
	cout << "\n5. Delete one" << endl;
	cout << "\n6. Return to main menu" << endl;

	cout << "\nEnter a choice (1 - 4): ";
}


int main()
{	
	// bool for loops
	bool start = true;
	bool subStart = true;
	// input option
	int option;
	int subOpt;



	//Gets Information from the txt files.
	
	department dep;

	department theArray[5];

	dep.populate(theArray);


	while (start) {
		subStart = true; //reset to true.
		menu();
		cin >> option;

		//If input is invalid for main menu
		if (option != 4 && option != 3 && option != 2 && option != 1) {

			cout << "\n" << option << " is not a valid choice. Try again..." << endl;

		}
		//Exit program
		if (option == 4) {
			start = false;
			dep.outputD(theArray);
			cout << "Thank you for using my program\n";
			system("pause");
		}

		//3rd choice
		if (option == 3) {

			while (subStart) {


				subP();
				cin >> subOpt;
				if (subOpt == 1) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 2) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 3) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 4) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 5) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				//Exit Loop
				else if (subOpt == 6) {
					subStart = false;
					cout << "Returning to Main Menu" << endl;
					system("pause");
					system("CLS");
				}

				else {
					cout << "\n" << subOpt << " is not a valid choice. Try again..." << endl;


				}
			}

		}

		if (option == 2) {
			while (subStart) {
				subS();
				cin >> subOpt;
				if (subOpt == 1) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 2) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 3) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 4) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 5) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 6) {
					//Exit loop
					subStart = false;
					cout << "Returning to Main Menu" << endl;
					system("pause");
					system("CLS");
				}

				else {
					cout << "\n" << subOpt << " is not a valid choice. Try again..." << endl;
				}
			}

		}


		if (option == 1) {
			while (subStart) {
				subM();
				cin >> subOpt;

				if (subOpt == 1) {
					dep.print(theArray);
					system("pause");
				}
				else if (subOpt == 2) {
					dep.add();
					dep.populate(theArray);
					system("pause");
				}
				else if (subOpt == 3) {
					dep.search(theArray);
					system("pause");
				}
				else if (subOpt == 4) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 5) {
					cout << "This  menu item is not implemented" << endl;
					system("pause");
				}
				else if (subOpt == 6) {
					//Exit loop
					subStart = false;
					cout << "Returning to Main Menu" << endl;
					system("pause");
					system("CLS");
				}

				else {
					cout << "\n" << subOpt << " is not a valid choice. Try again..." << endl;
				}
			}

		}
	
				
		}

	}
	


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
#pragma once
#include <string>
#include "Staff.h"
using namespace std;


struct personal
{
	string gender;
	string birthDate;
};

struct contact
{
	string phone;
	string email;
};



class staff : public department
{
private:
	//variable
	//department departID;
	string staffId;
	string staffName;
	personal info;
	contact details;

public:
	//defualt contructers
	staff();
	
	//getters
	string getSID();
	string getSName();
	//setters
	void setSID(string p);
	void setSName(string n);
	//print
	void printS(staff staffArray[]);

	//Other Functions.
	void addStaff();
	void populateS(staff staffArray[]);
	void searchS(staff staffArray[]);
	void outputS(staff staffArray[]);


};



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
#ifndef DEPARTMENT_H
#define DEPARTMENT_H

#include <string>
#include "Department.h"

using namespace std;

class department
{
private:
	//variable
	string nameD;
	string id;
public:
	//defualt contructers
	department();
	department(string i, string d);
	//getters
	string getID();
	string getname();
	//setters
	void setID(string p);
	void setName(string n);
	//print
	void print(department thearray[]);

	//Other Functions.
	void add();
	void populate(department thearray[]);
	void search(department thearray[]);
	void outputD(department thearray[]);


};
#endif




it works for me since department.h is included before staff.h in main.cpp.

But I do notice that you are including Department.h in the header that defines department, and likewise for Staff.h, which isn't the reason for any errors since my code works even if this is true, the only way this code can fail is if the file with department is actually named Staff.h and likewise with the other file, since you load department.h before staff.h, which makes this code work for me (even if there are large problems with your code).

OR it may be possible that you have files that you haven't shown us which can change the order the headers are parsed (much more likely).

Also I can make an essay about what is wrong with your code, but you should probably read more tutorials/ larger than one file examples on C++ since you have a lot to learn, and C++ will punish you if you think you can get away with figuring it out the basics by trial and error (especially with the fact you are writing your code C-ish, if you want to use C data, read C tutorials).
If the code in Staff.h depends on definitions in Department.h, then Staff.h should include Department.h.

Why do you have header files including themselves? What good could that ever possibly do?
Topic archived. No new replies allowed.