如何判断一个类的实例化对象是什么类?
-
2012年8月17日 3:42
比如说我现在实例化一个自定义类:CHuman* human
那我在之后如何让编译器自定判断它是什么类。也就是说,如何知道指针所指向的类为什么类。
- 已编辑 yshkcj 2012年8月17日 3:42
全部回复
-
2012年8月17日 5:53版主
你只要把RTTI选项打开,并一起就可以动态识别对象是什么类型。附加的条件是,对象可能多占用些内存。
麻烦把正确答案设为解答。
-
2012年8月17日 8:03版主
// compile with: /GR /EHsc
#include <typeinfo.h>
typeid( xxx ).name()Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.
- 已标记为答案 yshkcj 2012年8月22日 15:52

