From 8581160102280376465
X-Google-Thread: f78e5,e2cfdf64f67c7793
X-Google-Attributes: gidf78e5,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: walter@digitalmars.nospamm.com ("Walter")
Newsgroups: comp.std.c++
Subject: Re: Eliminating uninitialised variables
Date: Wed, 22 Sep 2004 22:42:58 GMT
Organization: Comcast Online
Lines: 44
Sender: mail2news@demon.net
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <JHm4d.5061$He1.1107@attbi_s01>
References: <memo.20040920104138.384A@brangdon.m> <FQO3d.21860$bB7.16246@newssvr27.news.prodigy.com> <6x14d.132741$3l3.96020@attbi_s03> <cismjo$5pr$1@panix2.panix.com>
NNTP-Posting-Host: news.news.demon.net
X-Trace: news.demon.co.uk 1095892982 24261 158.152.254.254 (22 Sep 2004 22:43:02 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Wed, 22 Sep 2004 22:43:02 +0000 (UTC)
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
X-Priority: 3
X-Spam-Checker-Version: SpamAssassin 2.64-mulga_r1 (2004-01-11) on 
	mulga.cs.mu.OZ.AU
X-Spam-Status: No, hits=-3.2 required=5.0 tests=AWL,BAYES_00,PRIORITY_NO_NAME 
	autolearn=no version=2.64-mulga_r1
X-MSMail-Priority: Normal
X-Received: (from fjh@localhost)
	by mulga.cs.mu.OZ.AU (8.12.10+Sun/8.12.9/Submit) id i8MMgwUC007353;
	Thu, 23 Sep 2004 08:42:58 +1000 (EST)
X-Path: comp-std-cpp-robomod!not-for-mail
X-NNTP-Posting-Date: Wed, 22 Sep 2004 22:06:33 GMT
X-Spam-Level: 
X-Delivered-To: std-c++@ucar.edu
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-Newsgroups: comp.std.c++
Path: g2news1.google.com!news1.google.com!news.glorb.com!news.zanker.org!news.amigo.co.uk!news.clara.net!wagner.news.clara.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!stump.algebra.com!devnull
Xref: g2news1.google.com comp.std.c++:2845


"Greg Comeau" <comeau@panix.com> wrote in message
news:cismjo$5pr$1@panix2.panix.com...
> In article <6x14d.132741$3l3.96020@attbi_s03>,
> Walter <walter@digitalmars.nospamm.com> wrote:
> >
> >"John Nagle" <nagle@animats.com> wrote in message
> >news:FQO3d.21860$bB7.16246@newssvr27.news.prodigy.com...
> >>     I'd suggest allowing initial values within class
> >> declarations, as in
> >>
> >> class T {
> >> char* p = 0;
> >> };
> >>
> >>     Yes, you can do the same thing in each constructor's
> >> initialization section.  But it's not as obvious by
> >> examination when someone left out an initialization,
> >> because the initialization and declaration are at
> >> different places.
> >
> >This is the approach D takes. It makes sense to put the default value
where
> >the declaration is, not off somewhere else.
>
> What does D do if it's also specified on a constructor (or multiple
> ones with different values), assuming is has such possibilities?

If an initialization of it is done in the constructor, it overrides the
default specified in the member declaration. Also, constructors can call
each other, making it practical to make 'layered' constructors.

One interesting aspect of this is that it behaves as if all the members have
their default values before even entering the constructor, this means that
if the constructor references a member before the constructor initializes
it, it still will get a predictable value (the default for that member)
rather than garbage.

---
[ 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                       ]



