It works if I change it to
Code:
template <typename OldType, typename NewType>
any & change_type(any & operand, OldType oldz, NewType newz)
{
try
{
any::placeholder * newcontent = new any::holder<NewType>(void_cast<NewType>(any_cast<OldType>(operand)));
// any::placeholder * newcontent = new any::holder<NewType>(static_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 << "BAD CAST" << endl;
}
return operand;
}
But that defeats the purpose because its terribly inconvenient to do this:
change_type(x,(int*)1,(char*)1);