title: Creating an Array List of Person Objects in C++
body: <p>I am trying to create an Array List of Person objects in C++ for a project I have. I am new to programming in C++ so I'm not really sure where to begin. The program builds successfully but I get a strange thread error at the line where I insert a person object into index 0. Could someone please point me in the right direction of how to insert objects into an arraylist? Thank you!</p>
  
  <p>Here is my Person class:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class Person
  {
  public:
      string fName;
      string lName;
      string hometown;
      string month;
      int day;
  
      Person();
      Person(string f, string l, string h, string m, int d);
      void print();
      int compareName(Person p);
  
  };
  
  Person::Person(string f, string l, string h, string m, int d) {
      fName = f;
      lName = l;
      hometown = h;
      month = m;
      day = d;
  }
  
  void Person::print() {
      std::cout &lt;&lt; "Name: " &lt;&lt; lName &lt;&lt; ", " &lt;&lt; fName &lt;&lt;"\n";
      std::cout &lt;&lt; "Hometown: " &lt;&lt; hometown &lt;&lt;"\n";
      std::cout &lt;&lt; "Birthday: " &lt;&lt; month &lt;&lt; " " &lt;&lt; day &lt;&lt;"\n";
  }
  </code></pre>
  
  <p>ArrayList.h</p>
  
  <pre><code>#ifndef __Project2__ArrayList__
  #define __Project2__ArrayList__
  
  #include &lt;iostream&gt;
  #include "Person.h"
  
  
  class ArrayList {
  public:
      ArrayList();
  
      bool empty() const {return listSize ==0;}
      int size() const {return listSize;}
      int capacity() const {return arrayLength;}
      void insert(int index, Person *p); //insertion sort
      void output();
  
  
  protected:
      Person* per;
      int arrayLength;
      int listSize;
  
  };
  #endif
  </code></pre>
  
  <p>ArrayList.cpp:</p>
  
  <pre><code>#include "ArrayList.h"
  #include &lt;iostream&gt;
  using namespace std;
  
  ArrayList::ArrayList()
  {
      arrayLength = 10;
      listSize = 0;
  }
  
  void ArrayList::insert(int index, Person *p)
  {
      per[index] = *p;
      listSize++;
  }
  
  
  void ArrayList::output()
  {
      for(int i=0; i&lt;listSize; i++)
      {
          per[i].print();
      }
  }
  </code></pre>