On Tuesday 23 July 2002 9:30 am, Jean-Marc Lasgouttes wrote: > >>>>> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: > > Lars> Think: what is the scope of objects inside a stl::container? > Lars> Does any copyinbg occur? > > Lars> Then think about what a scoped_ptr is. > > Lars> Now realize that you have to use a shared_ptr instead. > > Actually, copying occurs, but I do not want it to. Is it possible to > add an object to a container without copying it? It seems that > Myobj obj(foo, bar); > myvec.push_back(obj); > makes a copy of the obj object. Can I avoid it? > > So, if I cannot avoid copying, would it be a reasonable alternative to > define an operator= for MenuItem that does _not_ copy the Menu > pointer? I do not need that, after all.
Copying of a pointer is not very expensive and stl::container<boost::shared_ptr<Menu> > is therefore pretty efficient...