Re: delete construct
moongeegee wrote:
I have a class as below:
class Dpost {
public:
void* operator new[](size_t) {
cout << "Allocating a Dpost" << endl;
throw 1;
Question: Why is this useful? You don't allocate anything. It just
fails over immediately.
}
void operator delete[](void* p) {
cout << "Deallocating a Dpost" << endl;
::operator delete[](p);
}
};
in the main function, I want to clean up the construct.
As nothing's ever allocated, what you need to clean up?
try {
......
} catch(int)
Dpost::operator delete[]();
What are you deleting here? Where's the object array you want to
delete, specifically?
}
However the compiler prompts me errors as below;
error: no matching function for call to 'Dpost::operator delete []()'
note: candidates are: static void Dpost::operator delete [](void*)
The operator delete[] is called whenever you delete an array of objects
of the Dpost class, i.e. if
a = new Dpost[10];
then
delete[] a;
will delete this array.
HTHH,
Thomas
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]