开发者

Boost array Initialization in C++

开发者 https://www.devze.com 2023-02-05 03:00 出处:网络
I need to declare a boost::array. I did it as boost::array<char, 116> buf; is there a possibility that I can declare with the size stored as a con开发者_运维百科stant that is initialized from pr

I need to declare a boost::array. I did it as boost::array<char, 116> buf; is there a possibility that I can declare with the size stored as a con开发者_运维百科stant that is initialized from property file. something like boost::array<char, BUFFER_SIZE> buf;

Any Help?


No. If you want a dynamically sizable array, use a std::vector

Reason for No is that the template parameter cannot be provided at run time (caveat: current standard)


If it's a constant available at compile-time, (meaning you #included your property file or something) then yes.

int const BUFFER_SIZE = 116;
boost::array<char, BUFFER_SIZE> buf;

is valid. If it isn't available at compile-time, then no.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号