如何判断两个类是否是父子关系?

摘自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));

 

posted @ 2020-01-20 16:11  castchen  阅读(598)  评论(0编辑  收藏  举报