目录

nothrow

描述 (Description)

这是一个nothrow常量,这个常量值用作operator new和operator new []的参数,表示这些函数在失败时不会抛出异常,而是返回空指针。

以下是std :: nothrow的声明。

		
extern const nothrow_t nothrow;

参数 (Parameters)

没有

返回值 (Return Value)

没有

异常 (Exceptions)

No-throw guarantee - 此成员函数永远不会抛出异常。

数据竞争 (Data races)

没有

例子 (Example)

在下面的示例中为std :: nothrow。

#include <iostream>
#include <new>
int main () {
   std::cout << "Attempting to allocate...";
   char* p = new (std::nothrow) char [1024*1024];
   if (p==0) std::cout << "Failed!\n";
   else {
      std::cout << "Succeeded!\n";
      delete[] p;
   }
   return 0;
}

输出应该是这样的 -

Attempting to allocate...Succeeded!
↑回到顶部↑
WIKI教程 @2018