title: To add dynamically in an array of objects(CD)?
body: <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  class CD
  {
  
  public : 
      void getCDdetails(CD *);
      void printCDD(CD *) const;
      int putCount() const
      {
      return count;
      }
  
  private :
  static int count;
  char Title[60];
  char Artist[60];
  char Type;
  int Tracks;
  };
  
  
  int CD :: count=0;
  
  void CD :: getCDdetails(CD * cd)
  {
  cd=new CD[putCount() + 1];  //THIS LINE IS NOT HELPING
      for(int j=putCount(); j &lt; 100; j++)
      {
      cout &lt;&lt; "\nTitle :";
      cin &gt;&gt; cd[j].Title;
      cout &lt;&lt; "\nArtist :";
      cin &gt;&gt; cd[j].Artist;
      cout &lt;&lt; "\nType :";
      cin &gt;&gt; cd[j].Type;
      cout &lt;&lt; "\nTracks";
      cin &gt;&gt; cd[j].Tracks;
      count++;
      cout &lt;&lt; "Details added, Press enter to continue";
      fflush(stdin);
      getchar();
      break;;
      }
      printCDD(cd);
  }
  
  
  void CD :: printCDD(CD * cd) const 
  {
  
  cout &lt;&lt; "\nThere are " &lt;&lt; putCount() &lt;&lt; " number of CD details in the database at  present";
      for(int j=0; j &lt; putCount(); j++)
      {
      cout &lt;&lt; "\nTitle : " &lt;&lt; cd[j].Title;
      cout &lt;&lt; "\nArtist : " &lt;&lt; cd[j].Artist;
      cout &lt;&lt; "\nType : " &lt;&lt; cd[j].Type;
      cout &lt;&lt; "\nTracks " &lt;&lt; cd[j].Tracks &lt;&lt; endl;
      }
      fflush(stdin);
      cout &lt;&lt; "\nPress enter to continue";
      getchar();
  }
  
  
  void display_menu();
  
  int main()
  {
  display_menu();
  return 0;
  }
  
  void display_menu()
  {
  CD * st;
  int choice;
  int j;
  for(;;)
  {
  system("clear");
  cout &lt;&lt; "\n\t\t\t\tCurrent number of CDs in the CD database is  " &lt;&lt; st[0].putCount();
  cout &lt;&lt; "\n1:Enter a CD detail"   \
       &lt;&lt; "\n2:Print all the CD details" \
       &lt;&lt; "\n3:Quit"  \
       &lt;&lt; "\nEnter your choice : ";
  cin &gt;&gt; choice;
       switch(choice)
       {
       case 1 :
          st[0].getCDdetails(st);
              break;
       case 2 :
              st[0].printCDD(st);
              break;
       case 3 :
             exit(0);
       default :
              cout &lt;&lt; "\nPlease enter valid choice";
              fflush(stdin);
              getchar();
              break;
       }
    }         
  }
  </code></pre>
  
  <p>This line(cd=new CD[putCount() + 1];) does not helps because everytime I go for adding a data to the object array then perhaps a new chunk of memory gets allocated and the data added previously gets lost</p>
  
  <p>example : when i add to the ist object its O.K</p>
  
  <pre><code> Current number of CDs in the CD database is  0
    1:Enter a CD detail
    2:Print all the CD details
    3:Quit
    Enter your choice : 1
    Title :a
    Artist :a
    Type :a
    Tracks1
    Details added, Press enter to continue
  
  There are 1 number of CD details in the database at present
  Title : a
  Artist : a
  Type : a
  Tracks 1
  
  Press enter to continue
  
  1:Enter a CD detail
  2:Print all the CD details
  3:Quit
  Enter your choice : 1
  Title :a
  Artist :a
  Type :a
  Tracks1
  Details added, Press enter to continue
  
  There are 1 number of CD details in the database at present
  Title : a
  Artist : a
  Type : a
  Tracks 1
  
                     Press enter to continue
  
                       Current number of CDs in the CD database is  1
  1:Enter a CD detail
  2:Print all the CD details
  3:Quit
  Enter your choice : 1
  Title :b
  Artist :b
  Type :b
  Tracks2
  Details added, Press enter to continue
  
  There are 2 number of CD details in the database at present
  **Title :
  Artist :
  Type :
  Tracks 0**   //ITS NOT DISPLAYING THAT WAS ADDED JUST BEFORE
  
  Title : b
  Artist : b
  Type : b
  Tracks 2
  </code></pre>
  
  <p>Press enter to continue</p>
  
  <p>If its painful to look at it can somebody show me some example how to dynamically add to an object array ( I am just trying to do with new operator first ) and I have not tried linked list if I am successful I will go ahead and use linked list also.</p>