So I assumed I had to tell it this would contain pointers as well. I changed the vector line to
vector <*person> occupants;
You can treat a vector just like an array. Do you know how arrays work?
When you declare a vector, you have to specify the type of the things you want to store in the vector. You list the type between the angled brackets. 'occupants' is the name of your vector, just like you have a name for an array that you declare. If you do this:
Code:
vector <*person>* occupants;
You are declaring a variable called 'occupants' that is a pointer to a vector(where the vector contains pointers to person objects). You probably don't want to do that. Keep it simple and declare your vector like this instead:
Code:
vector<*person> occupants;
You can treat that vector just like you would an array that stores pointers to person objects.
All pointers have to be dereferenced to get the thing they point to:
Code:
int num = 10;
int* ptr = # //ptr equals the 'address of' num
int total = *ptr;
If you have an object that is stored in a variable, you call one of the object's member functions like this:
Code:
Person bob;
bob.someMemberFunction();
Now, if you have a pointer to an object and you want to call one of the object's methods, you first need to dereference the pointer with '*' to get the object, and then you use the dot operator to call the method:
Code:
Person bob;
Person* ptr = &bob; //ptr equal the 'address-of' bob
(*ptr).someMemberFunction();
However, having to type '(*ptr).' is a pain in the neck, so there is a shorthand syntax '->':
ptr->someMemberFunction();
The '->' is an instruction to dereference the pointer to give you the object, and then use the dot operator to call the function.
Code:
occupants->push_back(*P) //instead of occupants.push_back
And the program crashes because of that line.
That line says to insert *P into the the back of the vector. What is *P? If P is a pointer to a person object, then *P is the person object. But if your vector was declared to store pointers to persons, then you can't insert person objects in the vector.