c++ - 将模板参数传递给基类,简洁的表示法

标签 c++ templates inheritance

是否有更简洁的方法将参数传递给基模板类?

template <class II, class ICI>
class GraphBase : public GraphBaseOfBase<II, ICI>
{ ... };

template <>
class GraphBase<std::vector<int>::iterator, std::vector<int>::const_iterator> :
    public GraphBaseOfBase<
        std::vector<int>::iterator,
        std::vector<int>::const_iterator>
{ ... };

最佳答案

您可以使用 using 来缩短使用的主要类型,例如:

using vec_it = typename std::vector<int>::iterator;
using vec_cit = std::vector<int>::iterator;

然后

 template <>
 class GraphBase : public GraphBaseOfBase<vec_it, vec_cit>
 {
     //...
 };

关于c++ - 将模板参数传递给基类,简洁的表示法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43273334/

相关文章:

c++ - Netbeans C++ 项目无法识别通过项目属性添加的源路径

java - 如何防止父类(super class)调用重写的子类方法?

c++ - 逐行改进 C++ 的读取文件?

templates - 如何在编译时捕获递归函数的结果?

c++ - 作为非类型模板参数的函数指针

c++ - 了解一个对象是否是整型或者是否是类类型有什么意义呢?

javascript - 为什么 Object.create 在 JavaScript 中的原型(prototype)继承方面没有达到我的预期

python - 在Python中访问基类中的成员?

c++ - float 分配不正确

python - 从 Python 接收 C++ 中的字符串