Buf*_*lls 1 c++ types static-typing
TYPE& dynamic_cast<TYPE&> (object);
TYPE* dynamic_cast<TYPE*> (object);
Run Code Online (Sandbox Code Playgroud)
例如,我们可以得到这样的类型.C++是静态类型语言,为什么我们可以在运行时获取类型
C++中的变量具有静态确定的类型.对象不一定.您只需要通过静态已知类型的变量处理对象.
例子:
int * p = new int[argc]; // there is an object whose dynamic type is int[argc]
Base * p = new Derived; // *p has dynamic type Derived
Base * q = rand() % 2 ? new Derived1 : new Derived2; // ???
Run Code Online (Sandbox Code Playgroud)