new (nothrow)操作符实际上是什么意思,为什么要使用它
What does new (nothrow) operator actually means and why should we use it?
请参阅c++工作草案
T* p1 = new T; // throws bad_alloc if it fails
T* p2 = new(nothrow) T; // returns 0 if it fails
但是在什么情况下new
运算符抛出(或者在new(nothrow)
的情况下返回0
)
在什么情况下new操作符抛出(或者new(nothrow)返回0)?
当没有足够的可用内存来分配对象时,
或者如果新对象的构造函数本身抛出异常
(在这种情况下,即使是new的nothrow-变体也会抛出,
ie。
相关文章:
- 为什么"do while"循环不断退出,即使条件计算结果为 false?
- 为什么在全局范围内使用"extern int a"似乎不行?
- 为什么在popback()操作之后,它仍然打印完整的矢量
- 为什么随机数生成器不在void函数中随机化数字,而在main函数中随机化
- 为什么两个不同的未命名名称空间可以共存于一个cpp文件中
- 为什么会发生堆损坏
- 为什么使用 "this" 指针调用派生成员函数?
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 为什么比较运算符如此快速
- 为什么 Serial.println(<char[]>);返回随机字符?
- scanf( "%d" , array[i] + 1)是什么意思?为什么+1在那里?
- 为什么左值不能改变自己。左值用户是什么意思?
- for 循环后的分号是什么意思?为什么第一个循环语句中有 j++
- "我"的意思,为什么在那里?
- 为什么这段代码有效?我的意思是会员是私人的
- 为什么这段代码不能正常工作???我的意思是,为什么当我运行它时它没有显示任何内容?
- 字符串数组[] = " " 是什么;意思是,为什么它有效?
- nan在C++中是什么意思?为什么pow(-4,-2.1)返回-nan
- 警告C4247和C4248是什么意思,为什么从Visual c++ 2005中删除
- new (nothrow)操作符实际上是什么意思,为什么要使用它