Article View: comp.std.c++
Article #3532Re: Q: default constructor for fundamental types?
From: Fergus Henderson
Date: Wed, 28 Feb 1996 07:25
Date: Wed, 28 Feb 1996 07:25
51 lines
2217 bytes
2217 bytes
jamshid@io.com (Jamshid Afshar) writes:
>James Kanze <kanze@lts.sel.alcatel.de> wrote:
>>Expressions of the form `int()' have always been allowed. A (fairly)
>>recent change to the draft standard states that they have the same
>>value as default static initialization (in this case, 0). The earlier
>>rules had the initailization undefined.
>
>Is the following legal?
>
> class Foo {
> int x;
> public:
> Foo()
> : x() // legal?
> {}
> };
Yes.
>and if so is it different than just:
>
> Foo::Foo() {}
Yes, they are different. The former is equivalent to
Foo::Foo() : x(0) {}
This can be deduced from the following sections of the working paper:
[class.base.init] 12.6.2/3
"if the *expression-list* of the *mem-initializer* is
omitted, the base class or member subobject is
default-initialized (see [dcl.init])"
[dcl.init] 8.5/5
"To default-initialize an object of type T means:
--if T is a non-POD class type ...;
--if T is an array type ...;
--otherwise, the storage for the object is zero-initialized."
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Technical Details
Message-ID:
<4h0lo0$q0f@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!in2.uu.net!bounce-backReferences:
<4glrdc$dqo@ra.ibr.cs.tu-bs.de> <4gsvhn$csi@clarknet.clark.net> <9602271131.AA18225@lts.sel.alcatel.de> <4gvte1$qvd@xanadu.io.com>Show Full Headers
Complete Article Headers
From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Message-ID: <4h0lo0$q0f@mulga.cs.mu.OZ.AU> X-Original-Date: 28 Feb 1996 04:29:52 GMT Path: arc1-ca.pugleaf.net!in2.uu.net!bounce-back Date: 28 Feb 96 07:25:11 GMT Approved: fjh@cs.mu.oz.au Newsgroups: comp.std.c++ Subject: Re: Q: default constructor for fundamental types? Organization: Comp Sci, University of Melbourne References: <4glrdc$dqo@ra.ibr.cs.tu-bs.de> <4gsvhn$csi@clarknet.clark.net> <9602271131.AA18225@lts.sel.alcatel.de> <4gvte1$qvd@xanadu.io.com> X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUBMTQEWeEDnX0m9pzZAQFJ/wF9HQY6cEzsjA3pzACiX7+Hd1oRkuv7+SoU J12TSvbUrkCGlawzDV5jFeSFK8b8Unx7 =tfEi