Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

The new and delete Operators

Native C++ classes support dynamic allocation and deallocation of objects by providing the new and delete operators. These operators allocate memory for objects from a pool called the free store. The new operator calls the special function operator new, and the delete operator calls the special function operator delete.

The new function in the Standard C++ Library supports the behavior specified in the C++ standard and throws a std::bad_alloc exception if memory allocation fails.

The C Runtime Library's new function throws a std::bad_alloc exception if memory allocation fails.

If you want to use the non-throwing version of new for the C Runtime Library, link your program together with nothrownew.obj. However, when you link with nothrownew.obj, new in the Standard C++ Library will no longer function.

For a list of the library files that contain the C Runtime Library and the Standard C++ Library, see C Run-Time Libraries.

Managed C++ classes provide the gcnew operator instead of new and delete. For more information, see Language Features for Targeting the CLR. Managed C++ supports automatic garbage collection.

Community Additions

ADD
Show:
© 2015 Microsoft