Re: Containers of iterators vs. containers of references
On Jan 25, 12:44 am, clark.cole...@att.net wrote:
You can't have a container of references; references aren't
objects. I would use a container of pointers, however.
Any recommendations for type of pointer?
A pointer to whatever type you wanted the reference to.
I started playing with shared_ptr but then I discovered that
Visual Studio does not yet support C++ TR1. I need the code to
run on both x86/Linux under g++ and Visual Studio.
I wouldn't bother with shared_ptr except in some special cases.
I find it fairly rare that a container should control the
lifetime of an object that isn't copiable (and if the object is
copiable, of course, the vector will contain objects, and not
pointers or references)---most of the time, objects which aren't
copiable are entity objects which control their own lifetime.
(One exception might be a container of polymorphic agents. In
such cases, I'll usually use an invasive reference counter in
the base class.)
If you do want shared_ptr, of course, you can get it from boost.
I'm pretty sure that recent versions of both g++ and VC++ can
handle Boost.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34