Hello ladies and gents,
Ive got this example of a program that I tried out wich shows some special possibilities to use new.
#include <iostream>
using namespace std;
int main()
{
int a[100]= {0};
for (int i = 0; i < 100; ++i)
a[i] = 100 * i;
int *p = new(a) int [5];
for (int j = 0; j < 5; j++)
cout<< p[j] << " "; // 0 10 20 30 40
cout<<endl;
double *pd = new (a + 5) double;
*pd = 12.34;
cout<< *pd <<endl; // 12.34
float *pf = new (a + 50) float (5.6F);
cout<< *pf <<endl; // 5.6
return 0;
}
Now, as a good hobbyist I'm trying to be, I tried to delete the pointer with
delete p;
But, euh..., that didn't work and gave my computer almost a hart attack :)
So I figured, it's got to do with the fact that the array a is connected to the pointer.
If I'm correct, then problem is, how do I delete it, do I use a loop in wich I delete everything in the array. Because I tought you only had to delete the pointer pointing to the first place?
Ive tried to use this:
delete [] p;
but got the same result, get message:
Debug Assertion Failed!
file: dbgheap.c
Line:1011
ANy help would be greatly appreciated ;)