> On 11 Apr 97, Kevin Campbell wrote to Paul Wankadia --
>> I'm wondering how to, from an object's constructor, to self-destruct.
>> E.g. if there is some kind of error, the object will NOT be created.
> KC> Overload the new operator.
> Oh crikey ...
> KC> If the object is created, return a pointer to it, else return NULL.
> ... but a good idea, IMO. Just tell me how to DO that ...
Simple. It's just the same as a standard class function entry or operator
overload. Define the function "void *operater new(size_t size)". Now make the
code for it as void *xxxx::operator new(size_t size){
}
Where xxxx is the function name.
In the function, you simply allocate the memory, and return a pointer,
alling
a terminate function if you like if you can't get the memory.
- Kev
--- FMail/386 1.02
---------------
* Origin: Mail shipped from Deimos Spaceport (2:259/17)
|