如何判断两个类是否是父子关系?
摘自NoahFrame源码
template<typename DerivedType, typename BaseType> class TIsDerived { public: static int AnyFunction(BaseType* base) { return 1; } static char AnyFunction(void* t2) { return 0; } enum { Result = (sizeof(int) == sizeof(AnyFunction((DerivedType*)NULL))), }; };
assert((TIsDerived<className, classBaseName>::Result));