Wednesday, January 6, 2010

operator new[] and delete[] C/C++

// operator delete[] example
#include < iostream >
#include < new >
using namespace std;

struct myclass {
myclass() {cout <<"myclass constructed\n";}
~myclass() {cout <<"myclass destroyed\n";}
};

int main () {
myclass * pt;

pt = new myclass[3];
delete[] pt;

return 0;
}

Output:

myclass constructed
myclass constructed
myclass constructed
myclass destroyed
myclass destroyed
myclass destroyed

No comments:

Post a Comment