Boost logo

Boost :

From: Victor A. Wagner Jr. (vawjr_at_[hidden])
Date: 2005-04-27 14:23:20

At Tuesday 2005-04-26 11:10, Philippe Mori wrote:

>> I have to classes.
>> class Car;
>> class Limousine : public Car{
>> ...
>> };
>> And two vector
>> vector<Car> Cars;
>> vector<Limousine> Limousines;
>> I want to set vector Limousines's to vector Cars( Cars = Limousines ).
>Since a Limousine is a Car, you should able to do
> Cars.insert(Cars.end(), Limousines.begin(), Limousines.end());
>at least if you have a recent compiler.

the OP should note that doing this is going to "slice" each Limousine down
to a Car.
IF the original intent (NOT stated) was to have a single vector which held
both Cars and Limousines then some other approach would be needed (such as
a vector<Car*> or better, one of the smart pointers instead of the raw Car*).

>Unsubscribe & other changes:

Victor A. Wagner Jr.
The five most dangerous words in the English language:
               "There oughta be a law"

Boost list run by bdawes at, gregod at, cpdaniel at, john at