From -6893042022509061198
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,75a9ad8b6ce88ef7
X-Google-Attributes: gidf78e5,public
From: Valentin Bonnard <bonnardv@pratique.fr>
Subject: Re: new class initializer syntax?
Date: 1997/02/03
Message-ID: <32F43AA4.EEA@pratique.fr>#1/1
X-Deja-AN: 214171330
references: <2.2.32.19970130014647.002b4150@central.beasys.com>
x-original-date: Sun, 02 Feb 1997 06:56:36 +0000
organization: Internet Way
x-auth: PGPMoose V1.1 PGP comp.std.c++
newsgroups: comp.std.c++
originator: austern@isolde.mti.sgi.com
x-mailer: Mozilla 2.0 (Macintosh; I; 68K)


David R Tribble wrote:
> 
> Thomas A. Horsley <Tom.Horsley@worldnet.att.net> wrote:
> > ...  I only declare the member variable in
> > one place - why do I have to initialize it in every $#@!  constructor when I
> > just want it to be initialized to zero in all (or most) of 'em anyway?
> >
> > Has the standard committee considered any kind of new syntax for something
> > like a "default initializer", so I can give a member an initial value in the
> > class declaration which will be used if I don't provide a different
> > initializer in the constructor?
> 
> I'm still of the opinion that member variables ought to be initialized
> to zero (0, 0.0, null) by default if they don't have explicit initializers
> in the class constructors.
> 
> All the other object-oriented languages guarantee that every variable (and
> every reference) has a well-defined initial value, so why not C++?  How
> many times have people been bitten by uninitialized data?  When will the
> madness stop?

Not every other OOL I know of: Ada does not in any way innitialise
vars and Ada 95 is OO; in Ada it's even undefined behaviour to do
'x := x' or 'if x <> 0 then x := 0 endif' if x has not been explicitly
set to some value.

Also default innitialisations may not be OK for large arrays.

-- 

Valentin Bonnard
mailto:bonnardv@pratique.fr
http://www.pratique.fr/~bonnardv (Informations sur le C++ en Francais)
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



