Re: what does this mean ?
- From: "John Carson" <jcarson_n_o_sp_am_@xxxxxxxxxxxxxxx>
- Date: Fri, 8 Jul 2005 02:37:56 +1000
"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message news:dh8vu1zurpc3.bpeiwb74kp4l$.dlg@xxxxxxxxxx
On Thu, 7 Jul 2005 11:23:54 +0300, Alex Blekhman wrote:
Probably, you're confusing it with: new CFoo vs. new CFoo().
Now, the question is, "What's the difference?"
By section 5.3.4/15 of the standard, the second form does value initialisation, the details of which are described in section 8.5/5.
To illustrate, consider the following as compiled by VC++ 8.0 Beta 2:
struct Test
{
int x, y;
};int main()
{
Test *ptr1 = new Test;
cout << ptr1->x << ',' << ptr1->y << endl; Test *ptr2 = new Test();
cout << ptr2->x << ',' << ptr2->y << endl; delete ptr1;
delete ptr2;
return 0;
}x and y are uninitialised in the first case and zero initialised in the second case. This is a change that occurred between the 1998 version of the standard and the 2003 version.
-- John Carson
.
- Follow-Ups:
- Re: what does this mean ?
- From: Doug Harrison [MVP]
- Re: what does this mean ?
- References:
- what does this mean ?
- From: Polaris
- Re: what does this mean ?
- From: Igor Tandetnik
- Re: what does this mean ?
- From: Lawrence Groves
- Re: what does this mean ?
- From: Alex Blekhman
- Re: what does this mean ?
- From: Doug Harrison [MVP]
- what does this mean ?
- Prev by Date: Re: FYI: Inserting "#undef UNICODE " at a beginning of a file is not always enough
- Next by Date: Re: what does this mean ?
- Previous by thread: Re: what does this mean ?
- Next by thread: Re: what does this mean ?
- Index(es):
Relevant Pages
|