关于C++中nothrow的某某某

前言

在学习C++中new的种种用法时,在operator new的其中一个重载版本中看一个参数nothrow,想弄清楚到底是什么意思?nothrow顾名思义,就是不抛出的意思嘛!不抛出啥,在C++中只有异常我们用抛throw来描述,那么它的出现是为了什么呢?

 

类型

nothow其类型是nothow_t,nothrow_t在头文件<new>被定义为一个空类,struct nothrow_t{},同时也定义了标准常量nothrow;

 

NEXT

常量
std::nothrow
extern const nothrow_t nothrow;

 

被用于operator new 和 operator new[]的参数,用于表明这些函数在出现错误的时候不会抛出异常,而是返回用返回一个空指针代替

默认情况下,当使用new运算符来尝试分配内存并且处理函数无法执行时,会引发bad_alloc异常。 但是,如果nothrow用作new的参数,它将返回一个空指针。

 

对于operator new 和 operator new[]的相关问题

请移步于我的另一篇博文----->http://www.cnblogs.com/SimonKly/p/7826651.html

                                                   

posted @ 2017-11-13 23:44  SimonKly  阅读(1385)  评论(0编辑  收藏  举报