C
Christian Meier
Hi NG
I don't know if this problem is system dependend but I don't think so.
So, here is my assumption: "delete" deletes a variable. "delete[]" deletes
an array. Is this correct so far?
And now check this code out:
#include <iostream>
using namespace std;
int main()
{
char * p[100];
for(int i = 0; i < 100; ++i) {
p = new char[200000];
} // for
for(int i = 0; i < 100; ++i) {
delete[] (p);
//delete (p); <-- this does the same on Linux with g++
} // for
}
p is pointing to an array, so why doesn't it matter whether I write
"delete" with or without "[]"?
Or is this only on my system?
Thanks!
Greets Chris
I don't know if this problem is system dependend but I don't think so.
So, here is my assumption: "delete" deletes a variable. "delete[]" deletes
an array. Is this correct so far?
And now check this code out:
#include <iostream>
using namespace std;
int main()
{
char * p[100];
for(int i = 0; i < 100; ++i) {
p = new char[200000];
} // for
for(int i = 0; i < 100; ++i) {
delete[] (p);
//delete (p); <-- this does the same on Linux with g++
} // for
}
p is pointing to an array, so why doesn't it matter whether I write
"delete" with or without "[]"?
Or is this only on my system?
Thanks!
Greets Chris