From 6364483800916606406
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,9709ea4462a20887,start
X-Google-Attributes: gidf78e5,public
From: cNpOp@aStPl-iAnMtSl.cPoAmM
Subject: explicit C(): suggestion of meaningful (and easy) extension
Date: 1999/03/05
Message-ID: <01J8GJN2T5428WW94O@mail2.new-york.net>#1/1
X-Deja-AN: 451535498
Approved: Fergus Henderson <fjh@cs.mu.oz.au>
X-Original-Date: Fri, 05 Mar 1999 05:08:35 -0500
Content-Type: text/plain; charset="us-ascii"
X-Complaints-To: news@news.unimelb.edu.au
X-Trace: izvestia.its.unimelb.edu.au 920636899 25331 128.250.29.16 (5 Mar 1999 12:28:19 GMT)
Organization: -
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBFAgUANt/NyuEDnX0m9pzZAQETgwF8DV2ZblUXsTv6bBXAd0QCSsYDUH/v97mc ksoaFHJZavWLdXnzqJUx1GBg2T7VWvnE =yiwu
Mime-Version: 1.0
NNTP-Posting-Date: 5 Mar 1999 12:28:19 GMT
Newsgroups: comp.std.c++

It often happens that a derived class constructor that should invoke a
non-default base class constructor omits it, thereby silently invoking
the default base class constructor. I have repeatedly found this (e.g.
e.g. in copy constructors) when called in to track down other people's bugs.

How about saying that "explicit C()" would imply that a derived
class constructor would need to explicitly invoke the base default ctor
if that constructor is intended.

In other words,
class C
{
   int _i ;
   explicit C(){}
   C(int j): _i(j){}
};
class D: public C
{
    D():C(){}  // rather than just D(){}
    D(){}                // Would at least warn that default ctor C() will
be used
    D(int j):C(j){}    // ok
    D(int j){}          // Would at least warn that default ctor C() will be
used
};

This should be easy to implement, one would think, even if merely as a
compiler warning,
without waiting for a language spec change.

Is there any compelling reason not to do this?

   David
   Due to spam, remove capitals from address below to reply and change '$'
to '@'.
   cNpOp$aStPl-iAnMtSl.cPoAmM
---
[ 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://reality.sgi.com/austern_mti/std-c++/faq.html              ]



