我有一个基类
template<typename T>
class Base {};
和一些派生类:
class DerivedInt : public Base<int> {}
class DerivedDummy : public Base<Dummy> {}
// where Dummy is some user-defined concrete type
template<typename E>
class DerivedGeneric : public Base<E> {}
我想写一个类型特征函数 f<DerivedType>::value
仅当存在类型 T
时才返回 true这样 DerivedType
继承自 Base<T>
.
我觉得 SFINAE 是要走的路……但我对元编程黑魔法不太熟悉。谢谢!
最佳答案
我相信type support templates在 C++11 中是你想要的,尤其是 std::is_base_of .
关于C++ 在编译时检查继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29531536/