I got a class student.
And a vector<student> listOfStudents.
Wanted to ask,which is best way to store this vector.
Which of the ways is the best way?method a or method b?
vector<student> listOfStudents; //method A
vector<student*> listOfStudents; //method B
It depends on the class student.
The first options is usually the best place to start, but if student is a base class, or if it is expensive or illegal to copy, then the second option might be better.
If you're gonna store pointers, you might as well store smart pointers.
There is no way that can be answered for the specific case without giving the definition of student.
I mean it could be a typedef for short for all we know...
if student has no polymorphic methods and a default constructor, storing student by value may be a good option. else, store by pointer.
if you have the option to do either, the best option depends on the usage context.