c++ using vector of employee pointers
<p>I have created my vector class template and I have already done my employee classes of hourly and I salaried. I want to use the vector of employee  pointers instead of the array of employee pointers, I'm trying to do that but when I run it just breaks while I have no error listed.
Also, I have used the <code>at</code> function like( <code>payroll.at(i)-&gt;writeFile(out);</code> ) to get access to an element, but I don't know what's wrong.
Any suggestion?
Thanks</p>

<p>here is my code:
myvector class template:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;cassert&gt;
#include &lt;algorithm&gt;

  const int CAPACITY = 4;
  template &lt;class T&gt;
  class  MyVector {
  public:

    MyVector();
    MyVector( int size);
    MyVector( int size, const T &amp; initial);
    MyVector(const MyVector&lt;T&gt; &amp; v);      
    ~MyVector();

    int capacity() const;
    int size() const;
    void push_back(const T &amp; value); 
    //T &amp; operator[](unsigned int index);  
    MyVector&lt;T&gt; &amp; operator=(const MyVector&lt;T&gt; &amp;);
    void clear();
    T at(int i);

    friend ostream&amp; operator&lt;&lt;(ostream &amp;out, const MyVector&lt;T&gt;&amp; );


  private:
    int applied;
    int my_size;
    int my_capacity;
    T * buffer;
    T * daArray;
};

template&lt;class T&gt;
MyVector&lt;T&gt;::MyVector()
{
  my_capacity = 0;
  my_size = 0;
  buffer = 0;
  applied = 0;
}

template&lt;class T&gt;
MyVector&lt;T&gt;::MyVector(const MyVector&lt;T&gt; &amp; v)
{
  my_size = v.my_size;
  my_capacity = v.my_capacity;
  buffer = new T[my_size];  
  for ( int i = 0; i &lt; my_size; i++)
    buffer[i] = v.buffer[i];  
}

template&lt;class T&gt;
MyVector&lt;T&gt;::MyVector(int size)
{
  my_capacity = size;
  my_size = size;
  buffer = new T[size];
}

template&lt;class T&gt;
MyVector&lt;T&gt;::MyVector( int size, const T &amp; initial)
{
  my_size = size;
  my_capacity = size;
  buffer = new T [size];
  for (unsigned int i = 0; i &lt; size; i++)
    buffer[i] = initial;
  //T();
}

template&lt;class T&gt;
MyVector&lt;T&gt; &amp; MyVector&lt;T&gt;::operator = (const MyVector&lt;T&gt; &amp; v)
{
  delete[ ] buffer;
  my_size = v.my_size;
  my_capacity = v.my_capacity;
  buffer = new T [my_size];
  for (int i = 0; i &lt; my_size; i++)
    buffer[i] = v.buffer[i];
  return *this;
}

template&lt;class T&gt;
void MyVector&lt;T&gt;::push_back(const T &amp; i)
{
  if (my_capacity == 0)
  {
    my_capacity = 1;
    my_size = 1;
    applied= 0;
    buffer = new T[1];
    buffer[0] = i;
  }
  else
  {
    if (applied+1 == my_capacity)
    {
      int newCapacity = my_capacity * CAPACITY;
      daArray = new T[newCapacity];
      for (int i = 0; i &lt; my_size; i++)
      {
        daArray[i] = buffer[i];  
      }
      my_capacity = newCapacity;    
      delete buffer;
      my_size++;
      applied++;
      buffer[applied] = i;
    }
    else
    {
      if (my_size == applied + 1)
        my_size++;
      applied++;
      buffer[applied] = i;
    }
  }
}

template&lt;class T&gt;
int MyVector&lt;T&gt;::size()const//
{
  return my_size;
}

template&lt;class T&gt;
int MyVector&lt;T&gt;::capacity()const
{
  return my_capacity;
}

template&lt;class T&gt;
MyVector&lt;T&gt;::~MyVector()
{
  delete[ ] buffer;
}

template &lt;class T&gt;
void MyVector&lt;T&gt;::clear()
{
  my_capacity = 0;
  my_size = 0;
  buffer = 0;
}

template &lt;class T&gt;
T MyVector&lt;T&gt;::at(int i)
{
  if (i &lt; 0 || i &gt; my_size -1)
  {
    string error = "Index is undefined";
    throw error;
  }
  return buffer[i];
}

template &lt;class T&gt;
ostream&amp; operator&lt;&lt;(ostream &amp;out, const MyVector&lt;T&gt;&amp; v)
{
  for (unsigned i = 0; i &lt; v.size(); i++)
  {
    out &lt;&lt; v[i] &lt;&lt; " ";
  }
  return out;
}
</code></pre>

<p>main</p>

<pre><code>int main() {
  MyVector&lt; employee*&gt; payroll;
  payroll.push_back(new Hourly ("H. Potter", "Privet Drive", "201-9090", 40, 12.00));
  payroll.push_back(new Salaried ( "A. Dumbledore", "Hogewarts", "803-1230", 1200));

  ofstream out;
  out.open(file);

  if (out.fail()) {
    cout&lt;&lt;" could not open the file"&lt;&lt;endl;
    system("PAUSE");

  }

  for (int i = 0; i &lt; SIZE; i++) {
    payroll.at(i)-&gt;writeFile(out);
  }
  out.close( );
}
</code></pre>
