Re: what wrong ??
- From: "Scot T Brennecke" <ScotBspamhater@xxxxxxxx>
- Date: Thu, 7 Jul 2005 12:48:11 -0500
[1] Yes. The standard behavior for the "new" operator is to allocate on the heap. It can actually
be overridden to behave differently; but if you don't change the default behavior, you'll get heap
memory.
[2] In the case of A1 and A2, you are allocating new A class objects (one on the stack, one on the
heap), and thereby invoking the A constructor for each. A2 is not an A class object as A1 is,
however. A2 is a pointer to an A class object. Same with A3. But since you did not tell the
compiler to create an A object for A3 to point to, no memory was allocated for an A object, and no
constructor will be called for that case. Stack memory was allocated for both A2 and A3 also. But
this memory is simply the 4 bytes each required to hold a pointer.
"collay" <mosan1981@xxxxxxx> wrote in message news:OPw3znxgFHA.2444@xxxxxxxxxxxxxxxxxxxxxxx
> Thank you!
> Yes,I have already known that I should use "->" operator.
> yet I have another two questions:
> [1]use "new" operator will allocate the memory space in heap area,I think.Am
> I right?
> [2]use"A A1" or "A* A2 = new A",it will allocate memory and invoke the class
> A`s constructor.
> but what is the action when I use "A* A3"? Does the compiler only
> allocate the memory and do not invoke the constructor??
.
- References:
- what wrong ??
- From: collay
- Re: what wrong ??
- From: Scot T Brennecke
- Re: what wrong ??
- From: collay
- what wrong ??
- Prev by Date: Re: what wrong ??
- Next by Date: Re: what wrong ??
- Previous by thread: Re: what wrong ??
- Next by thread: Re: what wrong ??
- Index(es):
Relevant Pages
|