G
Gianni Mariani
Alex said:What is difference between
delete p;
and
delete(nothrow)p;
?
Is "nothrow" a typedef ?
Alex said:What is difference between
delete p;
and
delete(nothrow)p;
?
Alex said:What is difference between
delete p;
and
delete(nothrow)p;
?
Thomas said:So it appears that the first is legal C++ and the second is a syntax
error.
Pete said:That's because you wrote the test case incorrectly. In fact, the second
is valid, and calls the nothrow version of operator new. Fix your test
case by adding #include <new>.
What is difference between
delete p;
and
delete(nothrow)p;
?
Similarly the same rule follows with delete,
when you delete a pointer and if it fails it will throw automatically
an exception.
> hello Alex,
> when you assign memory dynamically theres a chance of failure of
> allocation of requested memory size especially with arrays. When new
> fails to allocate the requested memory it throws a bad_alloc exception
> of base class exception. Some compilers version returns a 0 instead for
> bad memory allocation.
> such as
> double *ptr = new(nothrow) double[5000000];
> requests the compiler to assign a 0 incase of bad allocation instead of
> throwing an exception of bad_alloc.
" is a valid C++ statement. I am sure it is part of the standard for C++0x and I don't _guess_ it is a new feature in the C++0x standard library (my compiler MSVC 9.0 compiles it fine).:perator delete(pointer, nothrow)
:perator delete (pointer, nothrow);
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.