I have these classes:
class Base
{
...
private:
std::vector<X> v;
};
class Derived : public Base
{
Derived(X*, int n);
};
where the constructor of Derived is passed an array of item Xs, which I need to insert into my vector v in the Base class. (X is a smart pointer)
Currently I see two ways to do this:
- Create a function in Base: InsertItem(X*) that will insert an item into the vector (1 by 1)
- Create a vector in Derived that contains the full list, then get it into Base by moving the entire vector.
I dont see any advantages to #2, but was wondering if #1 was a good solution, or if there are better ways to do this.
Thanks!