Topic: Forwarding ctors


Author: James.Kanze@dresdner-bank.com
Date: 1999/02/17
Raw View
795@clipper.ens.fr>,
  Valentin Bonnard <bonnard@clipper.ens.fr> wrote:
>
> Steve Clamage wrote:
>
> > Lawrence Crowl has suggested the language be extended to allow
> > "forwarding constructors".  Example:
> >         class T {
> >                 T(int); // the "real" constructor
> >                 T() : T(3) { } // forwarding constructor
> > This pair of constructors would have the effect of
> >                 T(int=3)
> > I don't see any problems with this extension, although one
> > compiler writer said he didn't see how to implement it.
>
> Who ?
>
> I natural way to implement it would be to translate it to
> an init function:
>
> T () { init (3); }
> T (int i) { init (i); }
>
> The problem is that sub-objects should not be constructed
> before the call to init. This can create problems if an exception
> is thrown, as the runtime may guess that inside init they are
> constructed.
>
> Note that before the call to init, *this as no dynamic type
> at all ! I am not sure that it's implementable but I guess
> it is.

I suspect that a large part of the problem was avoiding calling the
constructors to base classes several times (or not at all), and to
ensure calling them in the correct order. My first draft would be:

1. If a forwarding constructor is used, no other initialization is
   allowed.

2. If a forwarding initialization is present, then the generated
   constructor calls the constructor it is forwarded to, without
   initializing anything else.  It then executes its body.

But I've not done any analysis to see what problems there might be with
this approach.

--
James Kanze                                           GABI Software, S   rl
Conseils en informatique orient    objet  --
                          --  Beratung in industrieller Datenverarbeitung
mailto: kanze@gabi-soft.fr          mailto: James.Kanze@dresdner-bank.com

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


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






Author: Valentin Bonnard <bonnard@clipper.ens.fr>
Date: 1999/02/15
Raw View
Steve Clamage wrote:

> Lawrence Crowl has suggested the language be extended to allow
> "forwarding constructors".  Example:
>         class T {
>                 T(int); // the "real" constructor
>                 T() : T(3) { } // forwarding constructor
> This pair of constructors would have the effect of
>                 T(int=3)
> I don't see any problems with this extension, although one
> compiler writer said he didn't see how to implement it.

Who ?

I natural way to implement it would be to translate it to
an init function:

T () { init (3); }
T (int i) { init (i); }

The problem is that sub-objects should not be constructed
before the call to init. This can create problems if an exception
is thrown, as the runtime may guess that inside init they are
constructed.

Note that before the call to init, *this as no dynamic type
at all ! I am not sure that it's implementable but I guess
it is.

--

Valentin Bonnard


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