Re: copying a vector of objects at runtime
Julian <julvar@gmail.com> wrote in
news:00c0d939-e3d2-4c2b-85b3-f49efec35285@59g2000hsb.googlegroups.com:
On Jul 10, 10:02?am, Joe Greer <jgr...@doubletake.com> wrote:
"Julian" <jul...@nospamtamu.edu> wrote
innews:g54akk$c32$1@news.tamu.edu:
I'm not really sure if I understand the first part of your response.
from what I understand (and please let me know if i'm on the wrong
track), vector<Load> can only store only Load objects. even if i try
to store an object of a class derived from Load, it still stores only
a Load object because it calls Load(const Load&) when you do a
push_back.
In my case, I want this vector to 'store' a combination of Load
objects AND other objects that are derived from Load.
hope this helps in describing my situation... and please let me know
if it better for me to use some other c++ strategy.
thanks,
Julian.
Ah yes, I forgot polymorphism... In that case, if your objects have
identity, that is, you really only want one instance of it, then you might
look at a smart_ptr (from either TR1 or boost) to manage lifetime of the
object and just copy the vector normally. Or you make your Load interface
contain a clone() method of some sort which has the object create a copy of
itself. A clone_inserter iterator can then be made which invokes this
method to get the clone of the object and use std::copy() as I described
elsewhere.
joe