初始化std :: array问题

时间:2017-12-05 15:08:15

标签: c++ arrays c++11

我有一段看起来像这样的代码

#define PINS 40
#include <array>

class test {
    typedef void (*fptr_t)();
    template<int PIN>
    void interrupt_cb_t() {}

    std::array<fptr_t, PINS> interruptTable =
    {
        interrupt_cb_t<0>, interrupt_cb_t<1>, interrupt_cb_t<2>, interrupt_cb_t<3>, interrupt_cb_t<4>,
        interrupt_cb_t<5>, interrupt_cb_t<6>, interrupt_cb_t<7>, interrupt_cb_t<8>, interrupt_cb_t<9>,
        interrupt_cb_t<10>, interrupt_cb_t<11>, interrupt_cb_t<12>, interrupt_cb_t<13>, interrupt_cb_t<14>,
        interrupt_cb_t<15>, interrupt_cb_t<16>, interrupt_cb_t<17>, interrupt_cb_t<18>, interrupt_cb_t<19>,
        interrupt_cb_t<20>, interrupt_cb_t<21>, interrupt_cb_t<22>, interrupt_cb_t<23>, interrupt_cb_t<24>,
        interrupt_cb_t<25>, interrupt_cb_t<26>, interrupt_cb_t<27>, interrupt_cb_t<28>, interrupt_cb_t<29>,
        interrupt_cb_t<30>, interrupt_cb_t<31>, interrupt_cb_t<32>, interrupt_cb_t<33>, interrupt_cb_t<34>,
        interrupt_cb_t<35>, interrupt_cb_t<36>, interrupt_cb_t<37>, interrupt_cb_t<38>, interrupt_cb_t<39>
    };
};

然而,当使用'g ++ -std = c ++ 11 test.cpp'进行编译时,我得到两个错误:

'test.cpp:22:5:错误:数组必须使用括号括起的初始值设定项进行初始化      };'

'test.cpp:22:5:错误:“std :: array”的初始化程序太多

但是我不明白为什么我得到这些,当我有一个括号封闭的初始化列表和列表中恰当数量的元素?

0 个答案:

没有答案