Boost logo

Boost Users :

Subject: Re: [Boost-users] Advise sought for container type
From: OvermindDL1 (overminddl1_at_[hidden])
Date: 2009-08-30 18:03:25


On Sun, Aug 30, 2009 at 11:47 AM, joel<joel.falcou_at_[hidden]> wrote:
> Archie14 wrote:
>>
>> Well, how would I declare std::vector? std::vector<what>?
>> Using boost::any will require me to do some sort of type discovery at run
>> time.
>> Thanks for pointing the boost::variant to me; that will work.
>>
>
> std::vector< boost::variant<GrassEater,MeatEater> > v;

Or instead of Boost.Any, create a base class for it all called like
AnimalBase that is non-templated, then your above templated Animal
class will be as it is, but subclasses from Animal, then put abstract
calls or whatever similar functionality in AnimalBase to link it all.

Variant is faster all around if you know all of your types before hand.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net