title: Array of Pointers to object declared within a class?
body: <p>So My Question is: I want to know how to delete the (accounts pointer array) so that I can fill the array back in with the contents of my dummyA array. I tried <code>delete[]</code> and <code>delete accounts[j]</code> with a for loop, but to no avail I keep getting an error: <code>_ASSERTE(_BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse));</code> Honestly, I have no Idea what this means..
  Upon research, my best guess is that my problem is that I'm deleting my array more than once but I don't know how..Essentially,my accounts array of pointers to new objects has an irrelevant object in the middle of the array, soooo I made a dummy to place all relevant objects into with the goal of erasing all objects in accounts then replacing the objects with the objects inside of dummy,I want to save memory and try to be efficient.. Any Takers??<br>
          // Header File<br>
      <strong>ifndef H_ChartOfAccounts</strong><br>
      <strong>define H_ChartOfAccounts</strong><br>
      <strong>include string</strong><br>
      <strong>using namespace std;</strong></p>
  
  <pre><code>const int size = 100;
  
  
  class cOfA
  {
  protected:
  int actNumber;
  string actName;
  int actType;
  static cOfA* accounts[size];&lt;Dynamic Array of Pointers to Object "In Question"
  static int totalAccounts;
  
  public:
  cOfA();
  virtual ~cOfA();
  void getAccount();
  static void createAccount();
  static void addAccount();
  static void delAccount();
  static void displayAccount();
  void saveAccount();
  };
  
  **endif**
  //&gt;Implementation File For Above Header File
  void cOfA :: delAccount()
  {
  int searchItem;
  char ch;
  
  cout&lt;&lt;"\nEnter the Account Number that you want to delete: ";
  cin&gt;&gt;searchItem;
  
  for ( int j = 0; j &lt; totalAccounts; j++ )
  {
      if ( accounts[j]-&gt;actNumber == searchItem )
      {
          cout&lt;&lt;"\nDo you want to delete this account: \n";
          cout&lt;&lt; accounts[j]-&gt;actName&lt;&lt;" / ";
          cout&lt;&lt; accounts[j]-&gt;actNumber&lt;&lt;" / ";
          cout&lt;&lt; accounts[j]-&gt;actType&lt;&lt;endl;
          cin&gt;&gt;ch;
  
          if(ch == 'y')
          {
              accounts[j]-&gt;actName = " ";
              accounts[j]-&gt;actNumber = 0;
              accounts[j]-&gt;actType = 0;
              totalAccounts--;
              break;
          }
          else
          {
              cout&lt;&lt;"\nEnter the Account Number you want to delete: ";
              cin&gt;&gt;searchItem;
          }
      }//end if
  }// for loop
  
  cOfA* dummyA[size];
  int l = 0;
  
      for ( int k = 0;k &lt; totalAccounts+1; k++ )
      {
          if( accounts[k]-&gt;actNumber != 0 )
          {
              dummyA[l] = new cOfA;
             *dummyA[l] = *accounts[k];
             l++;
          }
  
      }//end for loop
  
  
  delete[] accounts;//&lt;--"When I compile, I get My Error Here"
  
  //Break Statement:"  _ASSERTE(_BLOCK_TYPE_IS_VALID(pHead-&gt;nBlockUse)); "
  
  
  int j = 0;
  while ( j &lt; totalAccounts )
  {
      accounts[j] = new cOfA;
      *accounts[j] = *dummyA[j];
      j++;
  }//end while loop
  delete[] dummyA;
  
  
  }
  </code></pre>