interesting question about new and nothrow new

Discussion in 'C++' started by George2, Jan 29, 2008.

  1. George2

    George2 Guest

    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
    George2, Jan 29, 2008
    #1
    1. Advertising

  2. George2

    James Kanze Guest

    On Jan 29, 4:42 am, George2 <> 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:
    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
    James Kanze, Jan 29, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dave

    nothrow and exceptions

    Dave, Oct 19, 2003, in forum: C++
    Replies:
    4
    Views:
    354
    Howard Hinnant
    Oct 20, 2003
  2. Roger Davis
    Replies:
    3
    Views:
    1,800
    Roger Davis
    Feb 25, 2005
  3. Lighter
    Replies:
    1
    Views:
    341
    Alan Johnson
    Aug 18, 2006
  4. Alex Vinokur

    new, delete and nothrow

    Alex Vinokur, Nov 23, 2006, in forum: C++
    Replies:
    4
    Views:
    487
    dasjotre
    Nov 23, 2006
  5. Virchanza
    Replies:
    11
    Views:
    831
    red floyd
    Dec 22, 2010
Loading...

Share This Page