C++ Array Resize crash
<p>I have a simple array class that uses template and have a size. I want to Resize it whenever it's full, but my program keeps crashing. 
the code is like this: </p>

<pre><code>    template&lt;class T&gt;
class Buffer:public File_ptr
{

    unsigned int siz;
    T *data;


public:

    ///konstruktor(size,filename,openmode)
    Buffer(unsigned int s=50,const char* n, const char* m):File_ptr(n,m),siz(s)
    {
        data= new T[siz];
        for(unsigned int i=0; i&lt;siz; ++i)
        {
            data[i]=0;
        };
    };

    ///destruktor
    ~Buffer()
    {
        delete[] data;
    }

    ///operator[]
    T&amp; operator[](unsigned int i)
    {
        if(i&gt;siz)
        {
            unsigned int newsize=siz*2;
            T* tmp=new T[newsize];
            for(unsigned int j = 0; j &lt; siz; j++)
            {
                tmp[j] = data[j];
            }
            siz=newsize;
            delete[] data;
            data=tmp;
            delete[] tmp;
        };
        return data[i];
    }

};  
</code></pre>

<p>the error comes at the operator[].(at least i think).
The main program is like this :</p>

<pre><code>int main()
{
   Buffer&lt;int&gt; k(20,"k.txt","w");
   Buffer&lt;char*&gt; s(20,"s.txt","w");
   k.printfile("HEY");
   s.printfile(5);
   for(unsigned int i=0;i&lt;23;i++){
    s[i]="Hey";
    cout &lt;&lt; s[i] &lt;&lt; endl;
   }


return 0;
}
</code></pre>

<p>Any help would be great! :)
Thanks!</p>