How do I typecast with type_info?

前端 未结 3 1810
暗喜
暗喜 2020-12-31 10:45

I\'ve stored a pointer to a type_info object.

int MyVariable = 123;
const std::type_info* Datatype = &typeid(MyVariable);

3条回答
  •  梦毁少年i
    2020-12-31 11:37

    I don't think such casting can be done. Suppose you could do "dynamic" casting like this at runtime (not to mean dynamic_cast). Then if you used the result of the cast to call a function the compiler could no longer do type checking on the parameters and you could invoke a function call that doesn't actually exist.

    Therefore it's not possible for this to work.

提交回复
热议问题