简体   繁体   English

“C风格数组”是什么意思,它与std :: array(C ++风格)有什么不同?

[英]What does “C-style array” mean and how does it differ from std::array (C++ style)?

我在阅读std :: array和std :: vector时遇到了这个问题。

A C-Style array is just a "naked" array - that is, an array that's not wrapped in a class, like this: C-Style数组只是一个“裸”数组 - 也就是说,一个没有包含在类中的数组,如下所示:

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 ). 而你所提到的“C ++风格数组”(非官方但流行的术语) - 像std::vector (或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. 这只是一个包装类(它实际上是一个C风格的数组),提供了边界检查和大小信息等方便的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM