Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > interesting question about new and nothrow new

Reply
Thread Tools

interesting question about new and nothrow new

 
 
George2
Guest
Posts: n/a
 
      01-29-2008
Hello everyone,


Why "if classes provide their own new but forget to provide nothrow
new too, nothrow new will be hidden and won't even work."

http://www.gotw.ca/publications/mill16.htm

BTW: I understand we should avoid nothrow new, and now I am just
interested to know why if only provide normal new, there will be
issues?


thanks in advance,
George
 
Reply With Quote
 
 
 
 
James Kanze
Guest
Posts: n/a
 
      01-29-2008
On Jan 29, 4:42 am, George2 <(E-Mail Removed)> wrote:

> Why "if classes provide their own new but forget to provide
> nothrow new too, nothrow new will be hidden and won't even
> work."


Because that's the way name lookup works. In general, new is no
exception.

> BTW: I understand we should avoid nothrow new,


The you understand wrong. The standard committee added nothrow
new for a reason. If you can handle insufficient memory
immediately, at the call location, then you should use nothrow
new. (Admittedly, most of the time, when you want to handle the
error condition immediately, you'll be allocating from a special
pool, and will use a special allocator function anyway.)

> and now I am just interested to know why if only provide
> normal new, there will be issues?


Will there be issues? I'd say that it depends on the
application, and that most of the time, there won't be issues.

--
James Kanze (GABI Software) email:(E-Mail Removed)
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
new(nothrow not even from constructor) Virchanza C++ 11 12-22-2010 12:55 AM
new, delete and nothrow Alex Vinokur C++ 4 11-23-2006 02:09 PM
Is there a way to write a memory leak detector supporting new(nothrow)? Lighter C++ 1 08-18-2006 06:11 AM
C++ nothrow new() problem under Irix Roger Davis C++ 3 02-25-2005 12:20 AM
nothrow and exceptions Dave C++ 4 10-20-2003 01:57 AM



Advertisments