Deleting dynamic array in C++ causes an error

I have a class called Myclass. In the main function, I have created an array object for this class. Whenever I try to delete this dynamically allocated array, the visual studio will say, Error: Debug Assertion Failed!. Expression: is_block_type_valid(header->_block_use). Can you please tell me what is causing this or show me an example of fixing this issue.

#include <iostream>
using namespace std;

class Myclass
    void print()
        cout << "Hello from Myclass" << endl;

int main()
    Myclass *obj[3] = { new Myclass, new Myclass, new Myclass };

    // Call each object's print function.
    for (int index=0; index < 3; index++)

    delete[] obj; //Error 

    return 0;



Myclass *obj[3] = { new Myclass, new Myclass, new Myclass };

is not a dynamically allocated array. It is an array with automatic storage, holding pointers to dynamically allocated objects. To properly clean up, you need:

delete obj[0];
delete obj[1];
delete obj[2];

Because every new must be matched with a delete, and you can only delete via delete[] something that was allocated via new[].

There is no need for any dynamic allocation here, just do:

Myclass obj[3] = {};