Using header <new>

J

Jonas Cord

Hi, is it necessary to #include the standard header <new> in standard
C++ when using dynamic memory management? Deitel & Deitel state that it
is, but I have hardly ever seen it used.
Thanks

Jonas
 
M

msalters

Jonas Cord schreef:
Hi, is it necessary to #include the standard header <new> in standard
C++ when using dynamic memory management? Deitel & Deitel state that it
is, but I have hardly ever seen it used.

No.

HTH,
Michiel Salters
 
C

Chris Theis

Jonas Cord said:
Hi, is it necessary to #include the standard header <new> in standard
C++ when using dynamic memory management? Deitel & Deitel state that it
is, but I have hardly ever seen it used.
Thanks

Jonas

The answers is yes & no. If you take at look at the standard (3.7.3 ISO
14882:2003(E)) you'll find that a program using new or delete is well formed
without including the header <new>. However, refering to std::bad_alloc and
std::size_t is ill formed unless the name was introduced by including the
appropriate header file.

HTH
Chris
 
J

Jonathan Mcdougall

Hi, is it necessary to #include the
standard header <new> in standard
C++ when using dynamic memory management?
Deitel & Deitel state that it
is, but I have hardly ever seen it used.

<new> contains:

.. class bad_alloc
.. set_new_handler()
.. new (nothrow)

and several already global functions. If
you don't use none of these three features,
you don't need to include <new>.


Jonathan
 

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

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top