Path: utzoo!attcan!uunet!clyde.concordia.ca!mcgill-vision!snorkelwacker!apple!voder!procase!roger From: roger@procase.UUCP (Roger H. Scott) Newsgroups: comp.lang.c++ Subject: Re: constructor called within constructor??? Message-ID: <174@logo.procase.UUCP> Date: 11 Jul 90 01:49:10 GMT References: <965@unet.UUCP> <11017@alice.UUCP> Reply-To: roger@procase.UUCP (Roger H. Scott) Organization: proCASE Corporation, Santa Clara, CA Lines: 44 Andrew Koenig's "helper" functions [build()] don't solve the problem of factoring out common *initialization*. For example, class Base { public: Base(int, double, char *, char *); ... }; class String { public: String(char *); ... }; class Derived : public Base { public: Derived() : Base(2, 4.6, "foo", "bar"), Mem1("aack"), Mem2("pfft"), myI(0), myJ(0) { } Derived(int i) : Base(2, 4.6, "foo", "bar"), Mem1("aack"), Mem2("pfft"), myI(i), myJ(0) { } Derived(int i, int j):Base(2,4.6,"foo","bar"),Mem1("aack"),Mem2("pfft"), myI(i), myJ(j) { } private: String Mem1, Mem2; int myI, myJ; }; A long time ago I asked the AT&T folks to define class Foo { public: Foo(); Foo(int i) : Foo(), myI(i) {} }; to mean "to construct a Foo object from an integer, construct a Foo object using the default Foo constructor and then execute the remainder of the Foo(int) constructor body". This is by analogy with "Derived() : Base() {}". Needless to say, my idea was not adopted.