I use boost :: any to have polymorphic types, I need the object to be bound to its base type.
class A { public: int x; virtual int foo()= 0; }; class B : public A { public: int foo() { return x + 1; } }; int main() { B* bb = new B(); boost::any any = bb; bb->x = 44; A* aa = boost::any_cast<A*>(any); }
The main function code throws the following error at runtime:
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::bad_any_cast> >' what(): boost::bad_any_cast: failed conversion using boost::any_cast Abort trap
If I change static_cast in boost :: any_cast code for reinterpret_cast, this will work. However, I am not sure about the consequences of this.
Do you have any ideas?
source share