Newsgroups: comp.lang.c++
Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!ira.uka.de!t500e0!fuchs
From: fuchs@t500e0.telematik.informatik.uni-karlsruhe.de (Harald Fuchs)
Subject: Re: Constructor question
Message-ID: <fuchs.670695206@t500e0>
Sender: news@ira.uka.de (USENET News System)
Organization: University of Karlsruhe, FRG
References: <1991Apr2.110623.22219@and.cs.liv.ac.uk>
Date: Wed, 3 Apr 1991 16:13:26 GMT
Lines: 26

markr@and.cs.liv.ac.uk writes:

>Can I call one constructor to class X explicitly from within another
>constructor to class X ?

>Example: constructor X::X( int i ) performs a lot of initialisation that needs
>to be done at the start of X::X( char *c ) too.  Can I write:

>X::X( char *c ) {
>	X( 5 );
>	// rest of stuff


>?  Or maybe something similar with different syntax?

>Apologies for turning the group into a tutorial session, but I can't find any
>reference to this in my C++ books.

That's because there is no such thing. When I have to do lots of
common initialization, I put it into a private member function
(e.g. void init ();) and call this function from the constructors.
Unfortunately, this won't work if you have to initialize constant or
reference data members. IMHO a hole in the language.
--

Harald Fuchs <fuchs@telematik.informatik.uni-karlsruhe.de>
