Delete a dynamically-allocated class instance in C++? : <p>In C++, I have a class A, and a second class B which contains an allocated array of A. What is the correct syntax for deleting an instance of A from B?</p>

<pre><code>class A
{
  ~A() {/*delete members of A which were dynamically allocated*/}
  //...members...
};

class B
{
  A *arrayOfA; // allocated by arrayOfA=new A[123];
};
</code></pre>

<p>This is what I have tried, to delete the i-th instance of A:</p>

<pre><code>// Code to delete an instance of A from B:
// delete arrayofA[i]; // gives a compilation error, because delete requires a pointer
delete &amp;arrayofA[i]; // compiles, but gives a runtime error
</code></pre>

<p>The destructor of A is being called, and seems to operate correctly. The error occurs in validation of the memory block for A (this is a debug build). Probably the error is caused by overwriting the heap allocation, but I would like to be sure the C++ syntax is correct for what I am trying to do.</p>

<p>64-bit Windows 7; Visual Studio 2017 v15.3.5</p>
