What is the correct implementation of erase function in vector class
<p>I'm trying to implement my own version of vector class without using iterators. Here is the parts which may be needed for the question.</p>

<pre><code>template &lt;typename T&gt;
class Vector {
public:
    ...

    ~Vector()
    {
        delete [] m_data;
    }

    ...

    void erase(size_t position)
    {
        if (position &gt;= m_size) {
            throw std::out_of_range("erasing an element out of bounds");
        }
        --m_size;
        for (size_t i = position; i &lt; m_size; ++i) {
            m_data[i] = m_data[i + 1];
        }
        m_data[m_size].T::~T();
    }

    ...

private:
    T* m_data;
    size_t m_size;
    ...
};
</code></pre>

<p>Below is a quote from <a href="http://cplusplus.com/reference/stl/vector/erase/" rel="nofollow">cplusplus.com</a> for <code>erase</code> function of <code>std::vector</code>:</p>

<blockquote>
  <p>This effectively reduces the vector size by the number of elements removed, calling each element's destructor before.</p>
</blockquote>

<p>So I tried to implement the same functionality by calling the destructor of the last duplicate element. The destructor of <code>m_data[position]</code> is unnecessary as it will be replaced by the next element.</p>

<p>The problem is that the code in the destructor of vector class <code>delete [] m_data</code> will also call the destructors for each element which will cause double deletion of memory and crash.</p>

<p>Can anyone help to write the correct erase function for my vector class?</p>
