首页 > 代码库 > 获取 c++ 类名

获取 c++ 类名

void PrintClassName(void *p)
{
type_info *** vtable = (type_info ***)(*(int*)p);
type_info ** v1 = vtable[-1];
type_info * v = v1[3];
printf("printName: %s\n", v->name());
}

前提:该类必须有virtual 成员

例如:

class class1
{
char a;
double b;
public:
virtual ~class1(){}

};