Article View: comp.std.c++
Article #3279Re: Const and Non-Const Constructors
From: Fergus Henderson
Date: Wed, 07 Feb 1996 18:25
Date: Wed, 07 Feb 1996 18:25
36 lines
2169 bytes
2169 bytes
smeyers@netcom.com (Scott Meyers) writes:
>A few months ago there was a discussion of whether the language should be
>extended so that const and non-const objects would have different
>constructors, the idea being that initialization for a const object might
>be different from initialization for a non-const object. My understanding
>is the committee has rejected that idea. Could someone please post a
>summary of the problems with the idea or point me to a place where I can
>find them?
One immediate problem is that to do it right would break backwards
compatibility, because you should not be able to invoke a non-const
constructor for a const object, just as you can't invoke a non-const
member function for a const object. Code such as
struct X { int a; X(); };
const X x;
would have to be declared illegal, to be replaced with
struct X { int a; X() const; };
const X x; ^^^^^
Breaking backwards compatibility like this would be a real problem.
There are other problems (e.g. initialization of arrays may become
very tricky) but I think the above problem would be sufficient to kill
the proposal.
--
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]
Technical Details
Message-ID:
<4f9pkj$av7@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!fido.asd.sgi.com!austernReferences:
<smeyersDMBEsy.5M8@netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fido.asd.sgi.com!austern From: fjh@munta.cs.mu.OZ.AU (Fergus Henderson) Newsgroups: comp.std.c++ Subject: Re: Const and Non-Const Constructors Date: 07 Feb 1996 10:25:20 PST Organization: Comp Sci, University of Melbourne Approved: austern@isolde.mti.sgi.com Message-ID: <4f9pkj$av7@mulga.cs.mu.OZ.AU> References: <smeyersDMBEsy.5M8@netcom.com> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 7 Feb 1996 08:58:59 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMRjupUy4NqrwXLNJAQFXLAIAkl8F8DwwzwVaxJMMK6P/kz8zYAA9k0JY YKYi+thMWgp/ICw9VJ1uJtSFeCcbb3rwdrEoQmY3TpPfEXbpgqDqsA== =dH3W Originator: austern@isolde.mti.sgi.com