开发者

is std:vector<char[30]> valid, or how to achieve this? (vector of fixed sized array?) [closed]

开发者_JAVA百科 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I would like to have a notion of 2d arrays with one dimension fixed.

something like a growing list of char arrays of length 30.

Can i do something like vector is that valid, or is there a way of achieving this


No: the type stored in a vector (or any other Standard Library container) must be both copyable and assignable. An array is neither.

You can (and should) use std::array (or, if your implementation doesn't support that, boost::array). The array class template provides a very lightweight container-like wrapper around an ordinary array; it can be used just like an ordinary array in most circumstances and has zero overhead (with a good implementation and with compiler optimizations turned on).

There is really no good reason to use an ordinary array (like char[30]) when you can use the array class template instead.


A std::vector of std::array sounds like a better idea.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜