Boost logo

Boost Users :

Subject: [Boost-users] [any] Is it possible to support polymorphism in boost::any?
From: Tang Jiang Jun (tangjiangjun_at_[hidden])
Date: 2010-09-06 10:27:56


It seems that boost::any does not support polymorphism in the following

class A {};
class B : public A {};

void foo( boost::any& _any )
A* p = any_cast< A* >( _any ); <-- Only succeed when _any contain a pointer
to a object that is exactly class A, but not any object that
is descendant of class A, like B.
do_some_thing( p );
catch( const bad_any_cast& )


void goo()
A* pa = new B;
boost::any a = pa;
foo( a );

Is it possible to make it support this polymorphism usage? Because
boost::any is a type-safe replacement of void*, I hope that boost::any has
the same polymorphic behavior as void*.

Tang Jiang Jun

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at