c++ - 模板结构成员的模板参数数量错误(1 应该是 3)

标签 c++ templates

我有一个这样的结构

namespace Binning_ {   
    template <typename data_type, uint32_t number_of_bins, bool uses_integrals>
    struct Binner {
        void setup();
    /* ... */

现在我要实现它。当然,我希望我必须以某种方式实现它

namespace Binning_ {  
    template <typename data_type, uint32_t number_of_bins, bool uses_integrals>
    void Binner<typename data_type, uint32_t number_of_bins, bool uses_integrals>::setup() { 
        /* ... */
    }

编译器不断告诉我错误的模板参数数量。

/home/udo/dev/libraries/dcf77/dcf77.cpp:305:81: error: wrong number of template arguments (1, should be 3)
     void Binner<typename data_type, uint32_t number_of_bins, bool uses_integrals>::setup() {
                                                                                 ^
/home/udo/dev/libraries/dcf77/dcf77.cpp:259:12: error: provided for 'template<class data_type, long unsigned int number_of_bins, bool uses_integrals> struct Binning_::Binner'
     struct Binner {
            ^

但是我不明白。当然,我必须传递 3 个模板参数。但为什么编译器只计数 1?

最佳答案

Binner 的参数列表中不得重复类型:

template <typename data_type, uint32_t number_of_bins, bool uses_integrals>
  void Binner<data_type, number_of_bins, uses_integrals>::setup() { 
        /* ... */
}

应该可以。

关于c++ - 模板结构成员的模板参数数量错误(1 应该是 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29110439/

相关文章:

c++ - 完全限制对文件夹的所有类型的访问

c++ - OpenGl 2d 缩放(使用缩放和平移而不是 glOrtho)

c++ - 如何从内部枚举中获取外部类名

C++ 关系运算符生成器

c++ - 防止 vector 项被移动

c++ - std::replace 有困难

c++ - 不同的枚举,相同的值

c++ - 在编译时找到最大公约数

javascript - Symfony - 从 javascript(前端)和 Controller (后端)访问 twig 模板

c++ - BOOST_FUSION_ADAPT_TPL_STRUCT 与模板成员