vector of pointers

I was wondering if there is a difference between:

1
2
3
vector<Course*> courses;
Course* cs = new CScourse(); //CScourse inherits Course
courses.push_back(cs);


and

1
2
3
void something(Course& c){ //c is also located on heap
courses.push_back(&c);
}


is there a difference between pushing a pointer and pushing reference?
is there a difference between pushing a pointer and pushing reference?

There is, although in both your examples above you're pushing a pointer to a Course object.
¿can you `store' references?
You are not pushing a reference. In the both cases you are pushing a pointer to an object of type Course I think that using CScourse() in the first example is a typo) . The difference is that in the first case we know that we are pushing a pointer that points to an object created in the heap while in the second case we can say nothing about where the object was created.
Last edited on
The same could be say with
1
2
3
void foo(Course *bar){
   courses.push_back(bar);
}
got it! Thnx!
Topic archived. No new replies allowed.