C++ 在编译时检查继承

标签 c++ templates

我有一个基类

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/

相关文章:

c++ - Python 还是 C++?移动设备编程

c++ - URLDownloadToFile API,如何异步使用?

PHP View ,使用模板

javascript - ExtJS 4.2.1 XTemplate 和子模板(静态)

c++将类与寺庙结合起来 - 声明其他功能?

c++ - 错误 : this declaration has no storage or type specifier

c++ - 如何附加不同的文件并提取它们以在我的代码中进行验证?

c++ - eclipse 开普勒 : #include "boost/filesystem.hpp" breaking debugging?

c++ - 默认模板参数是否符合单一定义规则?

c++ - 省略 C++ 模板参数列表时的区别