You can treat a vector just like an array. Do you know how arrays work?
So I assumed I had to tell it this would contain pointers as well. I changed the vector line to
vector <*person> occupants;
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:
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:
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:
If you have an object that is stored in a variable, you call one of the object's member functions like this:
int num = 10;
int* ptr = # //ptr equals the 'address of' num
int total = *ptr;
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:
However, having to type '(*ptr).' is a pain in the neck, so there is a shorthand syntax '->':
Person* ptr = &bob; //ptr equal the 'address-of' bob
The '->' is an instruction to dereference the pointer to give you the object, and then use the dot operator to call the function.
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.
occupants->push_back(*P) //instead of occupants.push_back
And the program crashes because of that line.