interesting question about new and nothrow new

G

George2

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
 
J

James Kanze

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.
 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top