Zdravim,
1 #include <iostream>
2 #include <cstring>
3 #include <vector>
4
5 using namespace std;
6
7 struct foo
8 {
9 int n;
10 char str[20];
11 };
12
13 typedef vector<vector<foo*>*>* TreePtr;
14
15 int main()
16 {
17 TreePtr *** tree = new TreePtr**[10];
18
19 for (int i = 0; i < 10; i++)
20 {
21 tree[i] = new TreePtr*[10];
22
23 for (int j = 0; j < 10; j++)
24 {
25 tree[i][j] = new TreePtr[10];
26
27 memset(tree[i][j], 0, 10);
28 }
29 }
30
31 if (!tree[1][2][3])
32 cout << 0 << endl;
33
34 for (int i = 0; i < 10; i++)
35 {
36 for (int j = 0; j < 10; j++)
37 {
38 delete [] tree[i][j];
39 }
40
41 delete [] tree[i];
42 }
43
44 delete [] tree;
45
46 return 0;
47 }
vsetko by sa, podla mna, zdalo vporiadku ale ked to prejdem valgrindom tak mi vyhodi takyto vystup:
$ valgrind ./hm
==13773== Memcheck, a memory error detector
==13773== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==13773== Using Valgrind-3.6.1 and LibVEX; rerun with -h for copyright info
==13773== Command: ./hm
==13773==
==13773== Conditional jump or move depends on uninitialised value(s)
==13773== at 0x400978: main (in /home/gman/hm)
==13773==
0
==13773==
==13773== HEAP SUMMARY:
==13773== in use at exit: 0 bytes in 0 blocks
==13773== total heap usage: 111 allocs, 111 frees, 8,880 bytes allocated
==13773==
==13773== All heap blocks were freed -- no leaks are possible
==13773==
==13773== For counts of detected and suppressed errors, rerun with: -v
==13773== Use --track-origins=yes to see where uninitialised values come from
==13773== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 4 from 4)
predsa tie ukazovatele v tree[i ][j][k] su inicializovane (na 0). Alebo sa to nepoklada za inicializaciu? Cize chcem sa spytat ako by sa dalo spravit aby som mal taketo 3-rozmerne pole ukazovatelov a kontrolovat ci ten-ktory ukazovatel ukazuje niekde zmysluplne alebo nie (0).