Anonymous     Text only     05 Sep 2011    
 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
template <class T>
class myarr
{
auto_ptr <T> ptr;
uint n;
public:
myarr ()
{
ptr.release ();
n = 0;
}
myarr (uint size)
{
ptr.reset (new T [size]);
if (!ptr.get ())
throw exception ("Not enought memory;");
n = size;
}
void resize (uint size)
{
ptr.release ();
ptr.reset (new T [size]);
if (!ptr.get ())
throw exception ("Not enought memory;");
n = size;
}
T& operator [] (uint i)
{
if (i < n)
return ptr.get () [i];
else
throw exception ("Wrong index in myarr;");
}
const T& operator [] (uint i) const
{
if (i < n)
return ptr.get () [i];
else
throw exception ("Wrong index in myarr;");
}
uint size () const
{
return n;
}
};