Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.edu!mips!pacbell.com!pacbell!unet!sugarfoot!noemi From: noemi@sugarfoot.net.com (Me) Newsgroups: comp.lang.c++ Subject: constructor called within constructor??? Message-ID: <965@unet.UUCP> Date: 4 Jul 90 04:50:18 GMT Sender: news@unet.UUCP Organization: Network Equipment Technologies, Redwood City Lines: 64 References: I don't normally subscribe to this group, so if I have violated any protocols or standards for questions, please forgive me. Please mail any responses directly to me, unless they are of general interest (I can't imagine that!!). Help!!!! I'm new to C++. 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: public: classname(); /* constructor 1 */ classname(int arg); /* constructor 2 */ /* constructor 1 */ classname:classname() { /* lots of things */ } /* constructor 2 */ classname:classname(int arg) { classname(); /* call constructor 1 */ privatevar = arg; /* "one extra thing" */ } Unfortunately, whatever constructor 1 does is getting lost. That is, private variables initialized inside constructor 1 are no longer thus after the call (at the "one extra thing" line). I've tried all of the following to use constructor 1, none so far have worked (since then I've discovered that assignment to "this" is considered obsolete and some compilers don't even allow it): classname(); /* constructor 1 */ this = new classname(); *this = classname(); this.classname(); /* doesn't compile */ this = this->classname(); /* doesn't compile */ classname this(); /* doesn't compile */ One grody solution is to make constructor 2 an exact copy of constructor 1, plus the extra line, but this offends my deeply ingrained committment to modularity. 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? noemi -- uucp: ames!unet!noemi inet: noemi@sugarfoot.net.com