新回归0 [英] new returning 0

查看:51
本文介绍了新回归0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我了解,这种行为早已被弃用,而且b $ b不是标准的。这是使用new

返回0而不是抛出异常来创建一个对象数组。我不是那个用代码处理

的人,但我告诉那个人他可能会期待一个例外并且因此给他带来了疯狂的追逐。我哪里出错了?


据我所知,没有覆盖operator new。没有

(std :: nothrow)。编译器是msvc ++ 8.

It is my understanding that this behavior has long been deprecated and
is not standard. That is the creation of an array of objects using new
returning 0 instead of throwing an exception. I''m not the one dealing
with the code but I told that person he might expect an exception and
thus sent him on a wild goose chase. Where did I go wrong?

As far as I know there''s no override of operator new. There''s no
(std::nothrow). Compiler is msvc++ 8.

推荐答案

Noah Roberts写道:
Noah Roberts wrote:

这是我的理解这种行为早已被弃用,并且

不是标准的。这是使用

new返回0而不是抛出异常来创建一个对象数组。我不是那个处理代码的人,但是我告诉那个人他可能会期待一个

的例外情况,因此给了他一个疯狂的追逐。我去哪了

错了?
It is my understanding that this behavior has long been deprecated and
is not standard. That is the creation of an array of objects using
new returning 0 instead of throwing an exception. I''m not the one
dealing with the code but I told that person he might expect an
exception and thus sent him on a wild goose chase. Where did I go
wrong?



一些旧的编译器没有正确实现''new''...

Some old compilers didn''t have the proper implementation of ''new''...


据我所知,没有覆盖operator new。没有

(std :: nothrow)。编译器是msvc ++ 8.
As far as I know there''s no override of operator new. There''s no
(std::nothrow). Compiler is msvc++ 8.



嗯?我认为它已在FAQ 5.8中得到解答...


V

-

请删除资金''回复电子邮件时的答案

我没有回复最热门的回复,请不要问

Huh? I think it''s answered in the FAQ 5.8...

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


Noah Roberts写道:
Noah Roberts wrote:

据我所知,这种行为早已被弃用,而且b $ b不是标准的。这是使用new

返回0而不是抛出异常来创建一个对象数组。我不是那个用代码处理

的人,但我告诉那个人他可能会期待一个例外并且因此给他带来了疯狂的追逐。我哪里出错了?


据我所知,没有覆盖operator new。没有

(std :: nothrow)。编译器是msvc ++ 8.
It is my understanding that this behavior has long been deprecated and
is not standard. That is the creation of an array of objects using new
returning 0 instead of throwing an exception. I''m not the one dealing
with the code but I told that person he might expect an exception and
thus sent him on a wild goose chase. Where did I go wrong?

As far as I know there''s no override of operator new. There''s no
(std::nothrow). Compiler is msvc++ 8.



1.你可以覆盖''operator new''

2.有std :: nothrow


从new返回0是一个方便的功能imo。对于过去10年b $ b年,人们一直在编写代码如

if(!(x = new classA)){handle_new_error(); }

1. you can override ''operator new''
2. there is std::nothrow

Returning 0 from new is a convenience feature imo. For the past 10
years, people have been writing code like
if( !(x = new classA) ){ handle_new_error(); }


Noah Roberts写道:
Noah Roberts wrote:

据我所知,这种行为早已被弃用了/>
不是标准的。这是使用new

返回0而不是抛出异常来创建一个对象数组。我不是那个用代码处理

的人,但我告诉那个人他可能会期待一个例外并且因此给他带来了疯狂的追逐。我哪里出错了?


据我所知,没有覆盖operator new。没有

(std :: nothrow)。编译器是msvc ++ 8.
It is my understanding that this behavior has long been deprecated and
is not standard. That is the creation of an array of objects using new
returning 0 instead of throwing an exception. I''m not the one dealing
with the code but I told that person he might expect an exception and
thus sent him on a wild goose chase. Where did I go wrong?

As far as I know there''s no override of operator new. There''s no
(std::nothrow). Compiler is msvc++ 8.



std :: nothrow在< new>中定义


#include< stdexcept>

#include< iostream>

#include< ostream>


int main()

{

int * pint = 0;

尝试

{

pint = new int [10];

}

catch(std :: bad_alloc& e)

{

std :: cout<< 新的失败:

<< e.what()

<< std :: endl;

}


delete [] pint;


pint = new(std :: nothrow)int [10];

if(!pint)

{

std :: cout<< new(std :: nothrow)失败 << std :: endl;

}

delete []品脱;


返回0;

}

std::nothrow is defined in <new>

#include <new>
#include <stdexcept>
#include <iostream>
#include <ostream>

int main()
{
int *pint = 0;
try
{
pint = new int[10];
}
catch (std::bad_alloc& e)
{
std::cout << "new failed: "
<< e.what()
<< std::endl;
}

delete[] pint;

pint = new(std::nothrow) int[10];
if (!pint)
{
std::cout << "new(std::nothrow) failed" << std::endl;
}
delete[] pint;

return 0;
}


这篇关于新回归0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆