Q:

C++ Help with pointers for a student

I am trying to create a vector and pass it to a function allowing the vector to be modified. Here is an abridged version of my code that doesn't work. 
void addStudent(vector<Student*>*);
int main()
{
   vector<Student*> students = new vector<Student*>;
   addStudent(students);
   return(0);
}
void addStudent(vector<Student*> *students)
{
   students->push_back(new Student("bob")); 
}

This code is compiling with errors. I think I'm not passing the pointer correctly but I'm not sure. 

A:

You've promised to give addStudent a pointer to a vector:
void addStudent(vector<Student*> *students)

so, use the address-of operator to get a pointer:
vector<Student*> students;
addStudent(&students);

There's nothing here that actually needs dynamic allocation, but if you did, note that new also returns a pointer:
vector<Student*>* students_ptr = new vector<Student*>();
addStudent(students_ptr);

Another option is to pass by reference:
void addStudent(vector<Student*>& students)
vector<Student*> students;
addStudent(students);

But I prefer the pointer, when the function is going to change its parameter.

