Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!emory!att!att!andante!alice!ark From: ark@alice.att.com (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: Constructor question Message-ID: <20164@alice.att.com> Date: 5 Apr 91 02:41:17 GMT References: <1991Apr2.110623.22219@and.cs.liv.ac.uk> Reply-To: ark@alice.UUCP () Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 27 In article <1991Apr2.110623.22219@and.cs.liv.ac.uk> markr@and.cs.liv.ac.uk writes: > Can I call one constructor to class X explicitly from within another > constructor to class X ? No. > 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 Do it this way: class X { private: common_stuff() { /* ... */ } public: X(int i) { common_stuff(); /* other stuff */ } X(char* c) { common_stuff(); /* other stuff */ } // and so on }; -- --Andrew Koenig ark@europa.att.com