开发者

What does "C-style array" mean and how does it differ from std::array (C++ style)?

开发者 https://www.devze.com 2023-03-29 04:43 出处:网络
I came across this question, while re开发者_如何学Cading about std::array and std::vector.A C-Style array is just a \"naked\" array - that is, an array that\'s not wrapped in a class, like this:

I came across this question, while re开发者_如何学Cading about std::array and std::vector.


A C-Style array is just a "naked" array - that is, an array that's not wrapped in a class, like this:

char[] array = {'a', 'b', 'c', '\0'};

Or a pointer if you use it as an array:

Thing* t = new Thing[size];
t[someindex].dosomething();

And a "C++ style array" (the unofficial but popular term) is just what you mention - a wrapper class like std::vector (or std::array). That's just a wrapper class (that's really a C-style array underneath) that provides handy capabilities like bounds checking and size information.

0

精彩评论

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