Item06. A number of sets of Array Formal Arguments

xiaoxiao2021-03-05  21

Item06. Array Formal Arguments

Cautious use

---------------------------------------- Decay: Array Automatically Convert to point to its head of the first element

---------------------------------------------

1. When using an array as a function of the function, the boundary information of the array is lost, so there is no need to specify the size of the array. Void average (int ary []); // int * ary

2. To explicitly specify the size of the array group, use reference Void Average (int (& ary) [12]); // can only be incorporated into an INT array of size 12

More access, you can use Templates: Template Void Average (INT (& Ary) [N]);

3, traditional method void average_n (int ary [], int size);

4, use STL containers, such as Vectorvoid Average (std :: vector ary);

5, multi-dimensional array is involved in a one-dimensional array of groups, but the array degradation is an array of arrays. Void Process (int ary []); // int (* ary) [20]

Template inline void process (int (& ary) [n] [m]) {process_2d (& ary [0] [0], n, m);}

转载请注明原文地址:https://www.9cbs.com/read-38285.html

New Post(0)