title: deleting an array of pointer to struct
body: <p>i have the following struct:</p>
  
  <pre><code>struct Message {
      Agent *_agent;
      double _val;
  };
  </code></pre>
  
  <p>and the following Ptrs array:</p>
  
  <pre><code>typedef Message* MessageP;
  MessageP *_msgArr;
  _msgArr = new MessageP[MAX_MESSAGES];
  </code></pre>
  
  <p>this is the method that inserts a Message to the array:</p>
  
  <pre><code>void Timing::AddMessage(Agent * const agentPtr, double val) {
  
      MessageP msgPtr = new Message;
      assert(msgPtr != 0);
  
      //assign values:
      (*msgPtr)._agent = agentPtr;
      (*msgPtr)._val = val;
  
      //add to messages array:
      assert(_msgArr != 0 &amp;&amp; _waitingMsgs&lt;MAX_MESSAGES);
      _msgArr[_waitingMsgs] = msgPtr;
      _waitingMsgs++;
  
  }
  </code></pre>
  
  <p>My question is about the deletion of this array. I would like to delete the array and all allocated structs.
  if i write:  </p>
  
  <pre><code>delete [] _msgArr  
  </code></pre>
  
  <p>will this delete also each allocated struct or will free only the allocated memory for the array?</p>
  
  <p>Is the correct way is to go over the entire array with a for loop and write </p>
  
  <pre><code>delete _msgArr[i]
  </code></pre>
  
  <p>and at last wite delete [] _msgArr to delete the allocated array
  ?</p>
  
  <p>thanks!</p>