Re: what does this mean ?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



"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

.



Relevant Pages