Constant-sized vector

前端 未结 7 875
無奈伤痛
無奈伤痛 2020-12-24 02:04

Does someone know the way to define constant-sized vector?

For example, instead of defining

std::vector

it will be

相关标签:
7条回答
  • 2020-12-24 02:27

    There is no way to define a constant size vector. If you know the size at compile time, you could use C++11's std::array aggregate.

    #include <array>
    
    std::array<int, 10> a;
    

    If you don't have the relevant C++11 support, you could use the TR1 version:

    #include <tr1/array>
    
    std::tr1::array<int, 10> a;
    

    or boost::array, as has been suggested in other answers.

    0 讨论(0)
提交回复
热议问题