problem with pointers

Hi, I am writing a program but every time i run it it crashes, I believe that it has to do with these two functions and the pointers, but i am unsure what exactly. Any help is greatly appreciated, thanks!

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
template <class T>
void container<T>::resize(int n)
{
    T *temptr;

    capacity = n;

    temptr = new T[n];

    if(n > count)
    {
        for(int i = 0; i < count; i++)

            temptr[i] = data[i];

            for(int i = count; i < n; i++)

            temptr[i] = T();
    }

    else
    {
        for(int i = 0; i < n; i++)

            temptr[i] = data[i];
    }

    count = n;

    delete[] data;

    data = temptr;
}

template <class T>
void container<T>::allocate()
{
capacity = capacity * 2;

    resize(capacity);

    delete data;
}
Why is line 42 deleting data?
Topic archived. No new replies allowed.