Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!alice!garry From: garry@alice.UUCP (garry hodgson) Newsgroups: comp.lang.c++ Subject: Re: constructor called within constructor??? Summary: let constructors call Init() member Message-ID: <11020@alice.UUCP> Date: 5 Jul 90 15:11:45 GMT References: <965@unet.UUCP> Organization: AT&T Bell Laboratories, Murray Hill NJ Lines: 36 In article <965@unet.UUCP>, noemi@sugarfoot.net.com (Me) writes: > > I'm trying to call a constructor routine (1) from withing another > constructor routine (2). Essentially, I want constructor 2 to do > exactly what constructor 1 does, plus one extra thing: ... > Both constructor routines (with 0 and 1 arguments) are necessary, so adding > "arg" to constructor 1 is not an option (I can't change a whole lot anyway > since this code belongs to a different deparment; hence I must tiptoe about.) > > What can I do? A habit I've gotten into is one I picked up from looking at InterViews code. That is, every class has an Init() member, which does all the "normal" initialization for the class. Each constructor then calls Init(). This solves the problem nicely. void Foo::Init() { do normal init stuff here } Foo::Foo() { Init(); } Foo::Foo( char *name ) { Init(); fileName = name; } garry hodgson