|< 1 2 >| | 13 Einträge, 2 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
template <typename T>
class Array
{
public:
Array() : m_container(0), m_size(0), m_lastindex(0) { }
Array(size_t size) : m_container(0), m_size(size), m_lastindex(0) { }
~Array() { if(m_container) free(m_container); }
size_t CountElements() const { return m_lastindex; }
size_t GetSize() const { return m_size; }
bool ReSize(size_t size)
{
if(size <= m_size) return false;
size_t len = sizeof(T) * size;
if(m_container == 0)
{
m_container = (T*)malloc(len);
memset(m_container, 0, len);
}
else
{
size_t oldlen = sizeof(T) * m_size;
m_container = (T*)realloc(m_container, len);
memset(m_container + oldlen, 0, len - oldlen);
}
m_size = size;
return true;
}
T & operator [](size_t idx)
{
if(idx >= m_size) ReSize(idx+1);
return m_container[m_lastindex = idx];
}
private:
T* m_container;
size_t m_size;
size_t m_lastindex;
};
Array< int > 1dintarray0(10);
Array< int > 1dintarray1(10);
Array< int > 1dintarray2(10);
Array< int > 1dintarray3(10);
Array< int > 1dintarray4(10);
Array< Array<int> > 2dintarray(5);
2dintarray[0] = 1dintarray0;
2dintarray[1] = 1dintarray1;
2dintarray[2] = 1dintarray2;
2dintarray[3] = 1dintarray3;
2dintarray[4] = 1dintarray4;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char 1darray0[16];
char 1darray1[16];
char 1darray2[16];
char 1darray3[16];
char* 2darrayptr[4];
2darrayptr[0] = 1darray0;
2darrayptr[1] = 1darray1;
2darrayptr[2] = 1darray2;
2darrayptr[3] = 1darray3;
void work(char** 2darrayptr)
{
// ...
}
work(2darrayptr);
|< 1 2 >| | 13 Einträge, 2 Seiten |