source: trunk/doc/src/snippets/code/doc_src_qvarlengtharray.qdoc@ 5

Last change on this file since 5 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 480 bytes
Line 
1//! [0]
2int myfunc(int n)
3{
4 int table[n + 1]; // WRONG
5 ...
6 return table[n];
7}
8//! [0]
9
10
11//! [1]
12int myfunc(int n)
13{
14 int *table = new int[n + 1];
15 ...
16 int ret = table[n];
17 delete[] table;
18 return ret;
19}
20//! [1]
21
22
23//! [2]
24int myfunc(int n)
25{
26 QVarLengthArray<int, 1024> array(n + 1);
27 ...
28 return array[n];
29}
30//! [2]
31
32
33//! [3]
34QVarLengthArray<int> array(10);
35int *data = array.data();
36for (int i = 0; i < 10; ++i)
37 data[i] = 2 * i;
38//! [3]
Note: See TracBrowser for help on using the repository browser.