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:

>>Hi,
>> 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 ).
>>zlf
>
>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: http://lists.boost.org/mailman/listinfo.cgi/boost
>

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


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk