keywords: C++, instanceof, typeof

Java has keyword instanceof and C# has function typeof to check object type at run-time.

Does C++ have equivalent of instanceof?
Answer is dynamic_cast:

if(NewType* v = dynamic_cast<NewType*>(old))
{
    // old was safely casted to NewType
    v->doSomething();
}

dynamic_cast only works when compiler RTTI enabled.

dynamic_cast is an operation with big cost.

Reference
https://stackoverflow.com/questions/500493/c-equivalent-of-instanceof


我与春风皆过客,你携秋水揽星河。----网络