It depends on the semantics you want to provide. In C ++ 11, you probably want to do something like:
Class::Class( vector<baddie*> input ) : baddies( std::move(input) ) {}
Which will move the memory from the copy to the member argument, and in C ++ 03 you probably write:
Class::Class( vector<baddie*> const & input ) : baddies( input ) {}
The vector with the copy will be initialized.
Note that this discussion applies only to the contents of the vector, and not to the data indicated by these baddie pointers. That is, in both cases there will be two vectors with pointers to refer to the same elements (i.e. only one copy of each baddie in memory with two pointers referring to it).
Depending on the semantics of your application, you can go from this intermediate shallow copy to either end: make a deep copy (i.e. create new baddie elements in memory so that the original and copy are completely disconnected as soon as the constructor completes) or you can’t do it at all, and just save the link / pointer so that both vectors are exactly the same (the insert inside or outside the class will be visible outside / inside the class).
Also, beware of pointer vectors, you need to manage memory manually before the vector is destroyed.
source share