什么是“C型阵列”是什么意思,它和std :: array(C ++ style)有什么不同? [英] What does "C-style array" mean and how does it differ from std::array (C++ style)?
问题描述
我遇到这个问题,在阅读有关 std :: array和std :: vector 。
I came across this question, while reading 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();
和一个C ++风格数组(非官方但热门术语)包装类像 std :: vector
(或 std :: array
)。这只是一个包装类(这真的是一个C风格的数组下),提供方便的功能,如边界检查和大小信息。
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.
这篇关于什么是“C型阵列”是什么意思,它和std :: array(C ++ style)有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!