Using the catch, I finally figured out that the problem is that the any_cast isn't working. I then found out that the templates are not reading something likeCode:template <typename OldType, typename NewType> any & change_type(any & operand) { try { any::placeholder * newcontent = new any::holder<NewType>(void_cast<NewType>(any_cast<OldType>(operand))); std::swap(operand.content,newcontent); delete newcontent; } catch (std::bad_cast) { cout << "TYPE1: " << typeid(OldType).name() << ' ' << "TYPE2: " << typeid(NewType).name() << endl; cout << "BOO HOO" << endl; return any::any(); } cout << "TESTING" << endl; return operand; }
change_type<int*,char*>(x);
as that, but as
change_type<int,char>(x);
which causes it to crash, because any_cast makes sure it returns the type that is currently stored in the any object.
Why isn't it taking the pointer?



LinkBack URL
About LinkBacks


