Constant-sized vector

前端 未结 7 921
無奈伤痛
無奈伤痛 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 
    
    std::array a;
    

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

    #include 
    
    std::tr1::array a;
    

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

提交回复
热议问题