关于运行时识别
一个项目,需要一个类型体系, 如:
class object {
object();
virtual ~object();
};
class type1 : public object
{
type1();
~type1();
}
现在要在runtime为识别一个对象的真实类型,
我现在有三个方案来识别一个对象类型,
一个是用现在的c++ RIIT:
type1* tmp = dynamic_cast<type1*>(obj),
if (tmp) ...
一个是在根类里加一个字段:
int __uuid, 不同的对象类型不同的值
for example: type1 contructor:
type1() : object(T_type1)
{
}
一个是用virtual function: int get_type(); 根类是虚的, 不同的子类返回不同的值,
for example:
int type1::get_type() {
return Istype1
}
这三种方式都能实现我要求的功能,但是不知道那一个性能最好。