【问题标题】:template template class specialization模板模板类专业化
【发布时间】:2015-06-22 19:37:03
【问题描述】:

我只是在学习模板模板类专业化。问题不大,详细解释一下。据我了解,std::uniform_int_distribution 是一个模板,而std::uniform_int_distribution<Type>uniform_int_distribution 提供类型的完全专业化。我在专业化类模板中传递它如下


主类

template <template <class> class Distribution,
    class Type,
    class Engine = std::mt19937>
class random_gen
{
    ....
}

类的专业化

template <class Type, class Engine>
class random_gen<std::uniform_real_distribution<Type>, Type, Engine>
{
    ...
}

发生的错误是

type/value mismatch at argument 1 in template parameter list for 'template<template<class> class Distribution, class Type, class Engine> class random_gen'

【问题讨论】:

    标签: c++ templates template-specialization


    【解决方案1】:

    特化仍然需要是模板模板参数。你传入了一个完整的类型。你想要:

    template <class Type, class Engine>
    class random_gen<std::uniform_real_distribution, Type, Engine>
    {
        ...
    };
    

    只是std::uniform_real_distribution,而不是std::uniform_distribution&lt;Type&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多