Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2006-10-10 10:31:51


Vaclav Vesely wrote:
> Fernando Cacciola wrote:
>
>>Vaclav Vesely wrote:
>>
>>>I would like to do somethink like this:
>>>
>>> class Base {...}
>>> class Derived: public Base {...}
>>>
>>> optional<Base> x = Derived();
>>> y->call_virtual_functions()
>>
>>It looks a lot like Boost.Any.
>>Have you looked at it?
>
>
> boost::any doesn't support derived classes as well. For example:
>
> any x = Derived();
> any_cast<Base>(x).virtual_function(); // throws bad_any_cast
>
> And moreover boost::any is too general. I want to store only values of Base
> and its derived classes.

Perhaps you can use Boost.PtrContainer:

typedef boost::ptr_vector< boost::nullable<Base> > OptionalContainer;

?

-Thorsten


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk