Stubborn classes don't want to be used
I am trying to make a function that resizes an array of my person class by recreating it with room for new information, and one that shortens it. Inside these two functions are the problems.
I am getting wierd compiler errors about my people not having a match. What am I doing wrong?
The first error is "no match for `person &= person *&'"
The second is "no match for `person &'"
The lines for both are marked out below, one inside the add_person function and the other in remove_person.
Code:
class room
{
public:
person *occupants;
unsigned short int num_persons;
room(void);
{
num_persons = 0;
}
bool add_person(person *person);
bool add_person(person *person);
};
class person
{
public:
//a few completely unrelated variables and functions are here
}
inline bool room::add_person(person *P = NULL)
{
if(!P) return false
if(num_persons == 0)
{ occupants = new person[1];}
else
{
person *new_list = new person[num_persons + 1];
for(unsigned short int index = 0; index < num_persons; index += 1)
{new_list[index] = occupants[index];}
delete [] occupants;
occupants = new_list;
}
num_persons += 1;
occupants[num_persons] = P; //This is line 123; error#1
return true;
}
inline bool room::remove_person(person *P = NULL)
{
if(!P) return false
if(num_persons == 1)
{delete [] occupants;}
else
{
num_persons -= 1;
short int skip = 0; //for skipping over the person being removed
person *new_list = new person[num_persons];
for(unsigned short int index = 0; index < num_persons; index += 1)
{
if(occupants[index] == P) skip = 1; //This is line 139; error#2
new_list[index] = occupants[index+skip];
}
delete occupants;
occupants = new_list;
}
return true;
}
And with the errors, after the first but before the second, there is also something that says "candidates are: class person & person::operator =(const person &)" which points to the ending brace for the person class.