A C++ newer, please do not de-vote...
I have the class Group and Person, Group has many Persons. There are many ways to implement this. The following 3 ways are common.
// 1. using dynamic pointer.
class Group {
Person *persons;
int size;
public:
Group(Person *ps, int sz);
};
// 2. using STL container.
class Group {
vector<Person> persons;
int size;
public:
Group(vector<Person> ps, int sz);
};
// 3. also STL container, but using pointer.
class Group {
vector<Person> *persons;
int size;
public:
Group(vector<Person> *ps, int sz);
};
I wonder that which one is the best way? is there any difference between the latter two ways? If using pointer, it's possible to have a memory leak.If using reference, we didn't need to consider leak problem, did it?