From: Jason Earl (Jason_at_[hidden])
Date: 2005-04-26 13:38:16
On 26 Ebr 2005, at 19:23, Caleb Epstein wrote:
> On 4/26/05, Philippe Mori <philippe_mori_at_[hidden]> wrote:
>> 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.
> And if you don't mind slicing your objects. You can't store
> polymorphic types directly in std containers.
> Caleb Epstein
> caleb dot epstein at gmail dot com
> Unsubscribe & other changes:
Well that's easy enough to get round, use pointers. if you are storing
objects in containers, it normally is good practice to use pointers
anyway because the STL passes data round by value, and not my reference
/ pointer, and therefore unless your objects are very lightweight
and/or have copy constructors, then storing objects by value is
normally a big no-no in most cases.
... One good exception to the rule here would be if you had smart
pointers, obviously these objects are copied into the container, and
these are lightweight and implement copy constructors / assignment
operators. Generally, if you are going to use pointers, depending on
the complexity of the object life-cycle, it is often wise to use
something like boost::shared_ptr , as it will reduce the the risks of
things like dangling pointers etc etc.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk