C++: Program crash while adding object to custom vector class
<p>I'm working on an email validation program for my cmpsci class and am having trouble with this one part.</p>

<p>What I'm doing is reading a list of valid top level domains from a text file into a vector class I wrote myself (I have to use a custom vector class unfortunately). The problem is that the program reads in and adds the first few domains to the vector all well and fine, but then crashes when it gets to the "org" line. I'm completely stumped why it works for the first few and then crashes.
Also, I have to use a custom string class; that's why I have the weird getline function (so I get the input in a char* for my String constructor). I've tried using the standard string class with this function and it still crashed in the same way so I can rule out the source of the problem being my string class. The whole program is quite large so I am only posting the most relevant parts. Let me know if more code is needed please. Any help would be awesome since I have no clue where to go from here. Thanks!</p>

<p>The ReadTlds function:</p>

<pre><code>void Tld::ReadTlds() {
    // Load the TLD's into the vector
    validTlds = Vector&lt;String&gt;(0); // Init vector; declaration from header file: "static Vector&lt;String&gt;validTlds;"
    ifstream in(TLD_FILE);
    while(!in.eof()) {
        char tmpInput[MAX_TLD_LENGTH];   // MAX_TLD_LENGTH equals 30
        in.getline(tmpInput, MAX_TLD_LENGTH);
        validTlds.Add(String(tmpInput)); // Crashes here!
    }
}
</code></pre>

<p>My custom vector class:</p>

<pre><code>#pragma once

#include &lt;sstream&gt;

#define INIT_CAPACITY 100
#define CAPACITY_BOOST 100

template&lt;typename T&gt; class Vector {
public:
 // Default constructor
  Vector() {
   Data=NULL;
   size=0;
   capacity=INIT_CAPACITY;
  }
 // Init constructor
 Vector(int Capacity) : size(0), capacity(Capacity) {
  Data = new T[capacity];
 }

 // Destructor
 ~Vector() {
  size=0;
  Data = NULL;
  delete[] Data;
 }

 // Accessors
 int GetSize() const {return size;}

 T* GetData() {return Data;}

 void SetSize(const int size) {this-&gt;size = size;}


  // Functions
  void Add(const T&amp; newElement) {
   Insert(newElement, size);
  }

  void Insert(const T&amp; newElement, int index) {
  // Check if index is in bounds
  if((index&lt;0) || (index&gt;capacity)) {
   std::stringstream err;
   err &lt;&lt; "Vector::Insert(): Index " &lt;&lt; index &lt;&lt; " out of bounds (0-" &lt;&lt; capacity-1 &lt;&lt; ")";
   throw err.str();
  }

   // Check capacity
   if(size&gt;=capacity)
   Grow();

   // Move all elements right of index to the right
   for(int i=size-1; i&gt;=index; i--)
   Data[i+1]=Data[i];

    // Put the new element at the specified index
   Data[index] = newElement;
   size++;
  }

  void Remove(int index) {
   // Check if index is in bounds
  if((index&lt;0) || (index&gt;capacity-1)) {
   std::stringstream err;
   err &lt;&lt; "Vector::Remove():Index " &lt;&lt; index &lt;&lt; " out of bounds (0-" &lt;&lt; capacity-1 &lt;&lt; ")";
   throw err.str();
  }

  // Move all elements right of index to the left
   for(int i=index+1; i&lt;size; i++)
    Data[i-1]=Data[i];
  }

 // Index operator
 T&amp; operator [] (int index) const {
  // Check if index is in bounds
  if((index&lt;0) || (index&gt;capacity-1)) {
   std::stringstream err;
   err &lt;&lt; "Vector operator[]:Index " &lt;&lt; index &lt;&lt; " out of bounds (0-" &lt;&lt; capacity-1 &lt;&lt; ")";
   throw err.str();
  }
 return Data[index];
 }

 // Assignment oper
 Vector&lt;T&gt;&amp; operator = (const Vector&lt;T&gt;&amp; right) {
   Data = new T[right.GetSize()];
  for(int i=0; i&lt;right.GetSize(); i++)
   Data[i] = right[i];
  size = right.GetSize();
  return *this;
 }

    private:
 T *Data;
 int size; // Current vector size
 int capacity; // Max size of vector

 void Grow() {
  capacity+=CAPACITY_BOOST;
  T* newData = new T[capacity];
  for(int i=0; i&lt;capacity; i++)
   newData[i] = Data[i];

  // Dispose old array
  Data = NULL;
  delete[] Data;
  // Assign new array to the old array's variable
  Data = newData;
 }
    };
</code></pre>

<p>The input file:</p>

<pre><code>aero
asia
biz
cat
com
coop
edu
gov
info
int
jobs
mil
mobi
museum
name
net
org  &lt;-- crashes when this line is read
pro
tel
travel
</code></pre>

<p>The error Visual Studio throws is:</p>

<pre><code>    Unhandled exception at 0x5fb04013 (msvcp100d.dll) in Email4.exe: 0xC0000005: Access violation reading location 0xabababbb.
</code></pre>
