If delete[] "knows" the size of any dynamically allocated array, shouldn't I be able to query its size somehow?
This is from cplusplus.com mixed with some of my own code to show what I mean:
// operator delete[] example
#include <iostream> // std::cout
struct MyClass {
MyClass() {std::cout <<"MyClass constructed\n";}
~MyClass() {std::cout <<"MyClass destroyed\n";}
};
int main () {
MyClass * pt;
MyClass * foo;
MyClass * bar;
pt = new MyClass[3];
delete[] pt;
foo = new MyClass[12];
delete[] &foo[0]; // this works
bar = new MyClass[33];
delete[] &bar[1]; // this does not work
return 0;
}
Motivation: If the first element of the array is special than any for-all would need only the last pointer and decrement until the first is detected... (I guess it could be "found" by looking for delete[] exception/error)