title: Dynamic memory allocation to array of pointers to object
body: <p>I have a <strong>class</strong> named <strong>Student</strong> </p>
  
  <pre><code>class Student
  {   string name;
      unsigned long int ID ;
      string email;
      unsigned short int year;
      public : 
           Student() // Constructor
           string getName(void);
           unsigned long int getID(void);
           string getEmail(void);
           unsigned short int getYear(void);   
  {
  </code></pre>
  
  <p>and another class named <strong>eClass</strong></p>
  
  <pre><code>class eClass {
   private:
   string eclass_name;
    Student* students[100];
    unsigned int student_count;
  
     public:
      eClass(string name)
      {
          student_count  =0 ; 
          eclass_name = name  ; 
      }
  
          bool exists(Student obj)
      {
          unsigned long int code = obj.getID();
          bool flag = TRUE ;
          for (unsigned int i = 0 ; i&lt;=student_count ; i++ )
          {
              unsigned long int st = (*students[i]).getID();
              if (code==st)
              {
                  flag = FALSE;
              }
          }
          return flag;
      }
  
  
          void add(Student&amp; obj)
      { 
          bool res = exists(obj);
          if (res)
          {
              students[student_count] = new Student(); //probably the problem is here
              *students[student_count] = obj ;  
              student_count++ ; 
          }
      }
  
      string getEclassName(void) { return eclass_name; }
      unsigned int getStudentCount(void) { return student_count; }
      Student getStudent(int i) { return *students[i-1]; }
  
  
       };    
  </code></pre>
  
  <p>The statement <strong>Student* students[100];</strong> must look exactly like this . For example I can't write something like this: Student* students[100]={} ;          </p>
  
  <p>And main() looks like this</p>
  
  <pre><code>    int main()
     {
       Student    JohnDoe("John Doe", 12345,  2,  "johndoe@gmail.gr");
       eClass Cpp("C++"); 
       Cpp.add(JohnDoe);
  
  
       }
  </code></pre>
  
  <p>Basically I have an array of pointers to Student objects and I want to allocate dynamically memory every time I want to add a new Student object.</p>
  
  <p>When I compile I get no errors but when I try to run the program the only thing I get is "Program_name.exe" stopped running...</p>
  
  <p>I'm pretty sure the problem has to do with memory allocation but I'm not able to find it and solve it.</p>
  
  <p>Any suggestions ? </p>