Function is not a memeber of for a Tree class (CS2039).

Pages: 12
Write a program that maintains a database containing data, Name and Birthday of your friends and relatives. You will be able to enter, remove, modify or search this data. Initially, you can assume that the names are unique. The program will be able to save and load the data in a file for use later. Design a class to represent the database and another to represent the people. Use binary search of people as a data member of the database class. I'm having trouble with the PeopleTree.cpp file it says that no class of this function. I'm trying to use the getBirthday and getName functions from the People.h file in the PeopleTree.cpp file. This project includes People.h, PeopleTree.h, and PeopleTree.cpp.
Enter -- Add a new person to you list.
Modify -- Change the name or birthday of a person.
Remove -- Remove a person from your list.
Search -- Display the information about a given person (unique name).
Query -- Run a query that displays the people by asking the user to enter a month.
Print -- List everyone in the database.

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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

// People.h
 #include "PeopleTree.h"
#include <string>
#include <iostream>
class People {
private: 
	std::string name;
	std::string birthday;

public:
	People();
	People(std::string name, std::string birthday);
	~People();

	void print();

	void setName(std::string name);
	void setBirthday(std::string birthday);


	std::string getName();
	std::string getBirthday();
};

People::People() {
	name = "";
	birthday = "";
}

People::People(std::string empName, std::string empBirthday) {
	name = empName;
	birthday = empBirthday;
}
People::~People() {

}
void People::setName(std::string n) {
	name = n;
}
void People::setBirthday(std::string b) {
	birthday = b;
}

std::string People::getName(){
	return name;
}

std::string People::getBirthday() {
	return birthday;
}

void People::print() {
	std::cout << "Name: " << name << std::endl;
	std::cout << "Birthday: " << birthday << std::endl;
}

//PeopleTree.h
#pragma once
#include "People.h"
#include <iostream>
#include <cstdlib>
#include <string>

class PeopleTree {

private:
	struct node {
		node* left;
		node* right;
		std::string value;
	};
	node* root;

    void insert(node*& currentPtr, node* newNode);
    void remove(node*& currentPtr, std::string name);
    void printInOrder(node* currentPtr);
    People* find(node* current, std::string name);
    void deleteTree(node* currentPtr);

public:
	PeopleTree();
	~PeopleTree();

	void insert(std::string name, std::string birthday);
	void insert(People& item);
	void remove(std::string name);
	bool search(std::string name);
	void find(std::string name);
	void printInOrder();

};
//PeopleTree.cpp
#include "PeopleTree.h"
#include <string>

PeopleTree::PeopleTree() {
	root = NULL;
}

PeopleTree::~PeopleTree() {
	deleteTree(root);
}

void PeopleTree::insert(node*& current, node* newNode) {

	//base case 1: current is null
	if (current == NULL) {
		current = newNode;
	}
	
	//general case 1: current->value < newNode->value
	else if (current->value < newNode->value) {
		/*will go to left node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->left, newNode);
	}
	//general case 2: current->value > newNode->value
	else if (current->value > newNode->value) {
		/*will go to right node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->right, newNode);
	}
}

void PeopleTree::insert(std:: string name,std::string birthday) {
	//new employee object 
	People* newPeople = new People(name, birthday);
	//create a node to add to tree
	node* newNode = new node;
	//set left and right inside newNode
	newNode->left = nullptr;
	newNode->right = nullptr;

	//now insert into tree
	insert(root, newNode);

}

void PeopleTree::insert(People& item) {

	//create new node
	node* newNode = new node;
	//set left and right pointers to nullptr
	newNode->left = NULL;
	newNode->right = NULL;

	insert(root, newNode);
}

void PeopleTree::deleteTree(node* current) {
	//base case
	if (current == NULL) {
		//do nothing
	}
	else {
		deleteTree(current->left);
		deleteTree(current->right);
		delete current;
	}
}

People* PeopleTree::find(node* current, std::string name) {
	//Base case 1:
	if (current == nullptr) {
		return nullptr;
	}
	//Base case 2:
	else if (current->value.getName() == name) {  // class has no memeber 
		return &current->value;
	}
	//General case:
	else {
		//go right or left
		if (name < current->value.getName()) { // class has no memeber 
			return find(current->right, name);
		}
		else {
			return find(current->left, name);
		}
	}
}

//wrapper for find

void PeopleTree::find(std::string name) {

	People* found = find(root, name);

	if (found == nullptr) {
		std:: cout << "That name is not in the tree." << std::endl;
	}
	else {
		std::cout << "Name: " << found->getName() << " Birthday: " << found->getBirtday() << std::endl;
		
	}
}


//Prints left nodes, current node, right nodes. Prints in descending order.
void PeopleTree::printInOrder(node* current) {

	//Base case: If null, do nothing

	//General case
	if (current != nullptr) {
		//prints the left nodes
		printInOrder(current->left);
		//prints the current node
		std::cout << current->value.getBirthday() << std::endl; // class has no memeber 
		//prints the right nodes
		printInOrder(current->right);
	}
}

void PeopleTree::printInOrder() {

	printInOrder(root);
}

void PeopleTree::remove(node*& current, std::string name) {

	//Base Case 1: Does the node exist?
	if (current == nullptr) {
		//do nothing
	}
	//Base Case 2: Item was found
	else if (current->value.getName() == name) { //Error occurs here 

		//Create a temp node pointer and set it equal to current
		node* tempPtr = current;

		//Check every case of nodes that may be attached to current node
		//Left and right point to null
		if (current->left == nullptr && current->right == nullptr) {
			current = nullptr;
		}
		//Left points to null, right points to somthing
		else if (current->left == nullptr && current->right != nullptr) {
			current = current->right;
		}
		//Left points to something, right points to null
		else if (current->left != nullptr && current->right == nullptr) {
			current = current->left;
		}
		//Left and right both point to something
		else {
			node* leftMost = current->right;
			while (leftMost->left != nullptr) {
				leftMost = leftMost->left;
			}
			leftMost->left = current->left;
			current = current->right;
		}
		delete tempPtr;
	}
	//General Case:
	else {
		if (name < current->value.getName()) {
			remove(current->left, name);
		}
		else {
			remove(current->right, name);
		}
	}

}

void PeopleTree::remove(std::string name) {

	remove(root, name);
}
Last edited on
The errors occur on L171, L177, L214, L232, L263.

For example it says getBirthday is not a member.
Last edited on
Please post the complete error message (all of them) exactly as it appears in your development environment. Those messages have important information embedded within them to aid in finding and fixing the problems.


By the way are you sure that in "current->value.getName()" that current is an instance of your class? My compiler seems to think that "current" is a std::string.


Error C2039 'getBirthday': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'

Error C2039 'getName': is not a member of 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>'

Also error on L170 says
Error C2440 'return': cannot convert from 'std::string *' to 'People *'
Line 3: Why are you including peopletree.h? This causes a circular include. prople.h does not use or need peopletree..

Line 27-27: It's unnecessary to set name and birthday to null strings. std:string is initialized by default to a null string.

Line 71: What is value and why is it a string? Shouldn't this be People * ?

Lines 126-138: You create null pointers to left and right nodes, but you don't store anything in value. Your search is not going to work.

Lines 140-149: ditto

Line 169,175,210,228,259: current->value is a std::string. std::string has no getNmae() function. Did you mean for value to be a People object?

Line 170: You're trying to return the address of a std::string. You've declared your function to return a pointer to a People object.

Line 194: getBirtday() Check your spelling. Birthday has an 'h' in it.

Here's a corrected version (not tested)
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272

// People.h
// #include "PeopleTree.h"  // * circular include - remove */
#include <string>
#include <iostream>
class People {
private:
	std::string name;
	std::string birthday;

public:
	People();
	People(std::string name, std::string birthday);
	~People();

	void print();

	void setName(std::string name);
	void setBirthday(std::string birthday);


	std::string getName();
	std::string getBirthday();
};

People::People() {
}

People::People(std::string empName, std::string empBirthday) {
	name = empName;
	birthday = empBirthday;
}
People::~People() {
}

void People::setName(std::string n) {
	name = n;
}

void People::setBirthday(std::string b) {
	birthday = b;
}

std::string People::getName() {
	return name;
}

std::string People::getBirthday() {
	return birthday;
}

void People::print() {
	std::cout << "Name: " << name << std::endl;
	std::cout << "Birthday: " << birthday << std::endl;
}

//PeopleTree.h
#pragma once
// #include "People.h"  /* included inline above */
#include <iostream>
#include <cstdlib>
#include <string>

class PeopleTree {

private:
	struct node {
		node* left;
		node* right;
		People * person;
	};
	node* root;

	void insert(node*& currentPtr, node* newNode);
	void remove(node*& currentPtr, std::string name);
	void printInOrder(node* currentPtr);
	People* find(node* current, std::string name);
	void deleteTree(node* currentPtr);

public:
	PeopleTree();
	~PeopleTree();

	void insert(std::string name, std::string birthday);
	void insert(People& item);
	void remove(std::string name);
	bool search(std::string name);
	void find(std::string name);
	void printInOrder();

};
//PeopleTree.cpp
// #include "PeopleTree.h"  /* included inline above */
#include <string>

PeopleTree::PeopleTree() {
	root = NULL;
}

PeopleTree::~PeopleTree() {
	deleteTree(root);
}

void PeopleTree::insert(node*& current, node* newNode) {

	//base case 1: current is null
	if (current == NULL) {
		current = newNode;
	}

	//general case 1: current->value < newNode->value
	else if (current->person->getName() < newNode->person->getName()) {
		/*will go to left node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->left, newNode);
	}
	//general case 2: current->value > newNode->value
	else if (current->person->getName() > newNode->person->getName()) {
		/*will go to right node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->right, newNode);
	}
}

void PeopleTree::insert(std::string name, std::string birthday) {
	//new employee object 
	People* newPeople = new People(name, birthday);
	//create a node to add to tree
	node* newNode = new node;
	//set left and right inside newNode
	newNode->left = nullptr;
	newNode->right = nullptr;

	//now insert into tree
	insert(root, newNode);

}

void PeopleTree::insert(People& item) {

	//create new node
	node* newNode = new node;
	//set left and right pointers to nullptr
	newNode->left = NULL;
	newNode->right = NULL;
	newNode->person = &item;
	insert(root, newNode);
}

void PeopleTree::deleteTree(node* current) {
	//base case
	if (current == NULL) {
		//do nothing
	}
	else {
		deleteTree(current->left);
		deleteTree(current->right);
		delete current->person;
		delete current;
	}
}

People* PeopleTree::find(node* current, std::string name) {
	//Base case 1:
	if (current == nullptr) {
		return nullptr;
	}
	//Base case 2:
	else if (current->person->getName() == name) {  // class has no memeber 
		return current->person;
	}
	//General case:
	else {
		//go right or left
		if (name < current->person->getName()) { // class has no memeber 
			return find(current->right, name);
		}
		else {
			return find(current->left, name);
		}
	}
}

//wrapper for find

void PeopleTree::find(std::string name) {

	People* found = find(root, name);

	if (found == nullptr) {
		std::cout << "That name is not in the tree." << std::endl;
	}
	else {
		std::cout << "Name: " << found->getName() << " Birthday: " << found->getBirthday() << std::endl;

	}
}


//Prints left nodes, current node, right nodes. Prints in descending order.
void PeopleTree::printInOrder(node* current) {

	//Base case: If null, do nothing

	//General case
	if (current != nullptr) {
		//prints the left nodes
		printInOrder(current->left);
		//prints the current node
		std::cout << current->person->getBirthday() << std::endl; // class has no memeber 
		//prints the right nodes
		printInOrder(current->right);
	}
}

void PeopleTree::printInOrder() {

	printInOrder(root);
}

void PeopleTree::remove(node*& current, std::string name) {

	//Base Case 1: Does the node exist?
	if (current == nullptr) {
		//do nothing
	}
	//Base Case 2: Item was found
	else if (current->person->getName() == name) { //Error occurs here 

		//Create a temp node pointer and set it equal to current
		node* tempPtr = current;

		//Check every case of nodes that may be attached to current node
		//Left and right point to null
		if (current->left == nullptr && current->right == nullptr) {
			current = nullptr;
		}
		//Left points to null, right points to somthing
		else if (current->left == nullptr && current->right != nullptr) {
			current = current->right;
		}
		//Left points to something, right points to null
		else if (current->left != nullptr && current->right == nullptr) {
			current = current->left;
		}
		//Left and right both point to something
		else {
			node* leftMost = current->right;
			while (leftMost->left != nullptr) {
				leftMost = leftMost->left;
			}
			leftMost->left = current->left;
			current = current->right;
		}
		delete tempPtr;
	}
	//General Case:
	else {
		if (name < current->person->getName()) {
			remove(current->left, name);
		}
		else {
			remove(current->right, name);
		}
	}

}

void PeopleTree::remove(std::string name) {

	remove(root, name);
}





Last edited on
@AbstractionAnon thanks for your advice. Here is my new code.
On L20 and L26 it says E0349 no operator ">" matches these operands


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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include "PeopleTree.h"
#include <string>

PeopleTree::PeopleTree() {
	root = NULL;
}

PeopleTree::~PeopleTree() {
	deleteTree(root);
}

void PeopleTree::insert(node*& current, node* newNode) {

	//base case 1: current is null
	if (current == NULL) {
		current = newNode;
	}
	
	//general case 1: current->value < newNode->value
	else if (current->value < newNode->value) { 
		/*will go to left node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->left, newNode);
	}
	//general case 2: current->value > newNode->value
	else if (current->value > newNode->value) {
		/*will go to right node and then keep calling function and going through the tree
		until it hits a nullptr*/
		insert(current->right, newNode);
	}
}

void PeopleTree::insert(std:: string name,std::string birthday) {
	//new employee object 
	People* newPeople = new People(name, birthday);
	//create a node to add to tree
	node* newNode = new node;
	//set left and right inside newNode
	newNode->left = nullptr;
	newNode->right = nullptr;

	//now insert into tree
	insert(root, newNode);

}

void PeopleTree::insert(People& item) {

	//create new node
	node* newNode = new node;
	//set left and right pointers to nullptr
	newNode->left = NULL;
	newNode->right = NULL;

	insert(root, newNode);
}

void PeopleTree::deleteTree(node* current) {
	//base case
	if (current == NULL) {
		//do nothing
	}
	else {
		deleteTree(current->left);
		deleteTree(current->right);
		delete current;
	}
}

People* PeopleTree::find(node* current, std::string name) {
	//Base case 1:
	if (current == nullptr) {
		return nullptr;
	}
	//Base case 2:
	else if (current->value.getName() == name) {  // class has no memeber 
		return &current->value;
	}
	//General case:
	else {
		//go right or left
		if (name < current->value.getName()) { // class has no memeber 
			return find(current->right, name);
		}
		else {
			return find(current->left, name);
		}
	}
}

People* PeopleTree::findMonth(node* current, std::string birthday) {
	//Base case 1:
	if (current == nullptr) {
		return nullptr;
	}
	//Base case 2:
	else if (current->value.getBirthday() == birthday) {  // class has no memeber 
		return &current->value;
	}
	//General case:
	else {
		//go right or left
		if (birthday < current->value.getBirthday()) { // class has no memeber 
			return find(current->right, birthday);
		}
		else {
			return find(current->left, birthday);
		}
	}
}
//wrapper for find

void PeopleTree::find(std::string name) {

	People* found = find(root, name);

	if (found == nullptr) {
		std:: cout << "That name is not in the tree." << std::endl;
	}
	else {
		std::cout << "Name: " << found->getName() << " Birthday: " << found->getBirthday() << std::endl;
		
	}
}

void PeopleTree::findMonth(std::string birthday) {

	People* found = find(root, birthday);

	if (found == nullptr) {
		std::cout << "That month is not in the tree." << std::endl;
	}
	else {
		std::cout << "Name: " << found->getName() << " Birthday: " << found->getBirthday() << std::endl;

	}
}



//Prints left nodes, current node, right nodes. Prints in descending order.
void PeopleTree::printInOrder(node* current) {

	//Base case: If null, do nothing

	//General case
	if (current != nullptr) {
		//prints the left nodes
		printInOrder(current->left);
		//prints the current node
		std::cout << current->value.getName() << current->value.getBirthday() << std::endl; // class has no memeber 
		//prints the right nodes
		printInOrder(current->right);
	}
}

void PeopleTree::printInOrder() {

	printInOrder(root);
}

void PeopleTree::remove(node*& current, std::string name) {

	//Base Case 1: Does the node exist?
	if (current == nullptr) {
		//do nothing
	}
	//Base Case 2: Item was found
	else if (current->value.getName() == name) { //Error occurs here 

		//Create a temp node pointer and set it equal to current
		node* tempPtr = current;

		//Check every case of nodes that may be attached to current node
		//Left and right point to null
		if (current->left == nullptr && current->right == nullptr) {
			current = nullptr;
		}
		//Left points to null, right points to somthing
		else if (current->left == nullptr && current->right != nullptr) {
			current = current->right;
		}
		//Left points to something, right points to null
		else if (current->left != nullptr && current->right == nullptr) {
			current = current->left;
		}
		//Left and right both point to something
		else {
			node* leftMost = current->right;
			while (leftMost->left != nullptr) {
				leftMost = leftMost->left;
			}
			leftMost->left = current->left;
			current = current->right;
		}
		delete tempPtr;
	}
	//General Case:
	else {
		if (name < current->value.getName()) {
			remove(current->left, name);
		}
		else {
			remove(current->right, name);
		}
	}

}

void PeopleTree::remove(std::string name) {

	remove(root, name);
}

//PeopleTree.h
#include "People.h"
#include <iostream>
#include <cstdlib>
#include <string>

class PeopleTree {

private:
	struct node {
		node* left;
		node* right;
		People value;
	};
	node* root;

    void insert(node*& currentPtr, node* newNode);
    void remove(node*& currentPtr, std::string name);
    void printInOrder(node* currentPtr);
    People* find(node* current, std::string name);
	People* findMonth(node* current, std::string birthday);
    void deleteTree(node* currentPtr);

public:
	PeopleTree();
	~PeopleTree();

	void insert(std::string name, std::string birthday);
	void insert(People& item);
	void remove(std::string name);
	//bool search(std::string name);
	void find(std::string name);
	void findMonth(std::string birthday);
	void printInOrder();

};


Last edited on
Here is my new code.


and it works OK? it compiles but does not work as expected? it doesn't compile? It doesn't link it ...

Wait a minute. I think the crystal ball is clearing and something's showing.... :)

In any case, as PeopleTree uses dynamic memory, then you need to provide a copy constructor and an operator=. The compiler provided versions will only do a shallow copy which is wrong when dynamic memory is used. if you don't at the moment want to provide function bodies for these functions, then mark them as deleted - so that code which tries to do a copy constructor or operator= won't compile:

1
2
3
4
5
6
class PeopleTree {
public:
    PeopleTree(const PeopleTree&) = delete;
    PeopleTree& operator=(const PeopleTree&) = delete;
//rest of class
};

Last edited on
On L20 and L26 it says E0349 no operator ">" matches these operands

Where are the exact error messages? This message probably has multiple lines telling you more about the message.

binary '>': 'People' does not define this operator or a conversion to a type acceptable to the predefined operator
OK. Our posts crossed.

value is of type People. So you need to provide an operator< and operator> that work with People. So perhaps (not tried):

1
2
3
4
5
6
7
8
9
bool operator<(const People& p1, const People& p2)
{
    return p1.getName() < p2.getName();
}

bool operator>(const People& p1, const People& p2)
{
    return p1.getName() > p2.getName();
}

You've ignored many of the errors I pointed out.

Lines 20,26: Since value is now a people object, you can't compare two people objects directly because you don't have comparison (<,>) operators.

If you had paid attention to the code I posted, you would see that in each case I called getName(), thereby comparing two std::strings.
Last edited on
Okay I'm trying it now.
Last edited on
At the end of people.h. You might need to mark them as inline if people.h is used in more than one compilation unit.

Note that people.h should have #pragma once at the beginning.
Here is my code for People.h file

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
#include <string>
#include <iostream>

class People {
private: 
	std::string name;
	std::string birthday;

public:
	People();
	People(std::string name, std::string birthday);
	~People();

	void print();

	void setName(std::string name);
	void setBirthday(std::string birthday);


	std::string getName();
	std::string getBirthday();
	bool operator >(People& obj) {
		return name > obj.name;
	}
	bool operator<(People& obj) {
		return name < obj.name;
	}
	bool operator==(People& obj) {
		return name == obj.name;
	}

};


People::People() {
	name;
	birthday ;
}

People::People(std::string empName, std::string empBirthday) {
	name = empName;
	birthday = empBirthday;
}
People::~People() {

}
void People::setName(std::string n) {
	name = n;
}
void People::setBirthday(std::string b) {
	birthday = b;
}

std::string People::getName() {
	return name;
}

std::string People::getBirthday() {
	return birthday;
}

void People::print() {
	std::cout << "Name: " << name << std::endl;
	std::cout << "Birthday: " << birthday << std::endl;
}
This should be obvious from the error message. Now that you've redefined node::value to be of type People, there's no way for the compiler to know how to compare one People to another. What does > mean for People? What does > mean?

You need to define these operators for the People class.

EDIT: Oops, was responding to an out-of-date view of the thread. Sorry.
Last edited on
It is working now. Thanks for your help everyone!
@Lacy9265, using code tags is a help, but when you jam multiple files into one set of code tags that reduces the helpfulness of using the tags.

Use separate sets of code tags for each file so the line numbers match up to what any errors are reported. Do this (just an example):

class.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#pragma once

class Foo
{
private:
   int m_Foo { };

public:
    Foo() { };
   ~Foo() { };

public:
   int  GetFoo() const;
   void SetFoo(int);
};

class.cpp:
1
2
3
4
5
6
7
8
9
10
11
#include "class.hpp"

int Foo::GetFoo() const
{
   return m_Foo;
}

void Foo::SetFoo(int f)
{
   m_Foo = f;
}

main.cpp:
1
2
3
4
5
6
7
8
9
#include <iostream>
#include "class.hpp"

int main()
{
   Foo foo;

   foo.SetFoo("test");
}


And you are not posting the EXACT error(s) you are getting. That would include what file(s) and line number(s) the error(s) are at. There's a deliberate error in the example above:

E0167   argument of type "const char *" is incompatible with parameter of type "int"   Project2   C:\Programming\My Projects\Project2\Project2\main.cpp   8	

Now we know the error is in main.cpp and is at line 8. And wow! It matches!

With each file having separate sets of code tags the line numbers do match up.
Last edited on
MS VS even gives the column number!
I've never noticed column numbers in any of my errors, which can be legion.

If'n I can get even close to the offending line of code -- sometimes where an error is reported is not where the actual error is, it might be a few lines earlier in the code - I'm happy since I can have a better look.
Pages: 12