Using other versions of the new operator

Further, a custom type can define a placement operator new, which allows you to provide one or more parameters to the custom new function. The syntax of the placement new is to provide the placement fields through parentheses.

The C++ Standard Library version of the new operator provides a version that can take the constant std::nothrow as a placement field. This version will not throw an exception if the allocation fails, instead, the failure can only be assessed from the value of the returned pointer:

    int *pi = new (std::nothrow) int [VERY_BIG_NUMBER];     if (nullptr == pi)      {         cout << "cannot allocate" << endl;     }     else     {         // use pointer         delete [] pi;     }

The parentheses before the type are used ...

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.