Topic: POD's initializations


Author: clcppmod-poster@not.a.valid.address ("Gianluca Silvestri")
Date: Sat, 26 Feb 2005 15:41:06 GMT
Raw View
Hi,
Where in the standard can I find explained the difference between these two
initializations:

struct POD
{
    int a;
};

int main()
{
    POD* p1 = new POD;    //indeterminat value of p1
    POD* p2 = new POD(); //default-inizialized
}

Thanks
Gianluca Silvestri


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: v.Abazarov@comAcast.net ("Victor Bazarov")
Date: Sun, 27 Feb 2005 21:59:00 GMT
Raw View
"Gianluca Silvestri" <clcppmod-poster@not.a.valid.address> wrote...
> Where in the standard can I find explained the difference between these
> two initializations:
>
> struct POD
> {
>    int a;
> };
>
> int main()
> {
>    POD* p1 = new POD;    //indeterminat value of p1
>    POD* p2 = new POD(); //default-inizialized
> }

5.3.4/15


---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: ron@sensor.com (Ron Natalie)
Date: Mon, 28 Feb 2005 17:06:01 GMT
Raw View
Gianluca Silvestri wrote:
> Hi,
> Where in the standard can I find explained the difference between these=
 two=20
> initializations:

>     POD* p1 =3D new POD;    //indeterminat value of p1
>     POD* p2 =3D new POD(); //default-inizialized

5.3.4 / 15
A new-expression that creates an object of type T initializes that object=
 as follows:
=97 If the new-initializer is omitted:
=97 If T is a (possibly cv-qualified) non-POD class type (or array thereo=
f), the object is defaultinitialized
(8.5). If T is a const-qualified type, the underlying class type shall ha=
ve a user-declared
default constructor.
=97 Otherwise, the object created has indeterminate value. If T is a cons=
t-qualified type, or a (possibly
cv-qualified) POD class type (or array thereof) containing (directly or i=
ndirectly) a member of
const-qualified type, the program is ill-formed;
=97 If the new-initializer is of the form (), the item is value-initializ=
ed (8.5);

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]