在保证创建的堆栈中创建的对象是什么? [英] are the objects created in the stack guarranted to have been created?

查看:90
本文介绍了在保证创建的堆栈中创建的对象是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


1.当主题消息时,是否已创建堆栈中创建的对象

已创建?

2.我如何验证这一点? (例如,对于在堆中创建的对象A * a = new A

可以检查为:if(a == NULL),或者尝试捕获bad_alloc异常)

TIA

解决方案

jimjim写道:

1.当主题sugest时,是否创建了对象堆栈保证已经创建了吗?


这个问题是什么意思?黑色宝石是黑色的吗?

2.我该如何验证? (例如,对于在堆中创建的对象A * a = new A
可以检查为:if(a == NULL),或者尝试捕获bad_alloc异常)



对。但这并不意味着他们被创造了,是吗?如果没有例外

发生,你只能确定内存已分配,至少如果我跟随你的逻辑关于在堆栈中创建......


V




您好,

1.随着主题的消化,堆栈中创建的对象是否已被创建?


保证调用适用的构造函数。是否

这使得你的对象处于一个明确定义的状态取决于你,如果你是b $ b是实现者。

2。我该如何验证? (例如,对于在堆中创建的对象A * a = new A
可以检查为:if(a == NULL),或者尝试捕获bad_alloc异常)



据推测,您的问题实际上是关于动态分配的数据

成员。您必须抛出(或捕获)异常,或提供

''isValid''方法。


/ david


对不起家伙我没有很好地解释自己。


再一次:


创建时动态的对象(A * a =新的A),有一种情况是堆可能会耗尽,因此任何创建对象的努力都会失败。 (记忆不会被分配)。出于这个原因,您应该检查

是否为== NULL,或者尝试捕获由新运算符抛出的bad_alloc异常




当你在堆栈上创建对象时,我应该假设分配给堆栈段的内存可能也会耗尽吗?如果问题是肯定的,我怎么能检查我试图创建的对象是否确实是创建的(就像我为动态分配内存一样)

b4)?


TIA


< da ******** @ warpmail。净>在消息中写道

news:11 ********************* @ g49g2000cwa.googlegro ups.com ...



jimjim写道:

你好,

1.当主题sugest时,是否在堆栈中创建对象
guarranted
创建了吗?



保证可以调用适用的构造函数。如果你是实施者,那么这是否会使你的对象处于一个明确定义的状态取决于你。

2.我如何验证这个? (例如对于在堆中创建的对象A * a =
new A
可以检查为:if(a == NULL),或者尝试捕获bad_alloc
异常)


据推测,您的问题实际上是关于动态分配数据的成员。您必须抛出(或捕获)异常,或提供
''isValid''方法。

/ david



Hello,

1. As the subject sugests, are the objects created in the stack guarranted
to have been created?
2. How can I verify this? (e.g. for objects created in the heap A *a = new A
one can check as: if ( a == NULL), or try to catch the bad_alloc exception)

TIA

解决方案

jimjim wrote:

1. As the subject sugests, are the objects created in the stack guarranted
to have been created?
What does this question mean? Are black stones black?
2. How can I verify this? (e.g. for objects created in the heap A *a = new A
one can check as: if ( a == NULL), or try to catch the bad_alloc exception)



Right. But that doesn''t mean they are created, does it? If no exception
occurs, you only can be sure that the memory was allocated, at least if
I follow your logic about "created in the stack"...

V




jimjim wrote:

Hello,

1. As the subject sugests, are the objects created in the stack guarranted
to have been created?
The applicable constructor is guaranteed to be called. Whether or not
this leaves your object in a well-defined state is up to you, if you
are the implementor.
2. How can I verify this? (e.g. for objects created in the heap A *a = new A
one can check as: if ( a == NULL), or try to catch the bad_alloc exception)



Presumably, your question is really about dynamically allocated data
members. You must throw (or catch) an exception, or provide an
''isValid'' method.

/david


Sorry guys I did not explain myself well.

Once again:

When you create objects dynamically (A *a = new A), there is the case that
the heap may become exhausted and therefore any effort to create objects
will "fail" (memory wont be allocated). For this reason, you ought to check
whether a == NULL, or try to catch the bad_alloc exception that is thrown
by the new operator.

When you create objects on the stack should I assume that the memory
allocated to the stack segment may become exhausted as well? If the anwer to
the question is positive, how can I check if the objects I tried to create
are indeed created (i.e. just like I did for dynamic allocation of memory
b4)?

TIA

<da********@warpmail.net> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...



jimjim wrote:

Hello,

1. As the subject sugests, are the objects created in the stack
guarranted
to have been created?



The applicable constructor is guaranteed to be called. Whether or not
this leaves your object in a well-defined state is up to you, if you
are the implementor.

2. How can I verify this? (e.g. for objects created in the heap A *a =
new A
one can check as: if ( a == NULL), or try to catch the bad_alloc
exception)



Presumably, your question is really about dynamically allocated data
members. You must throw (or catch) an exception, or provide an
''isValid'' method.

/david



这篇关于在保证创建的堆栈中创建的对象是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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