Path: utzoo!utgpu!watserv1!watmath!att!rutgers!usc!jarthur!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: constructor called within constructor??? Message-ID: <55850@microsoft.UUCP> Date: 16 Jul 90 18:57:44 GMT References: <965@unet.UUCP> <11017@alice.UUCP> <174@logo.procase.UUCP> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Organization: Microsoft Corp., Redmond WA Lines: 34 In article <174@logo.procase.UUCP> roger@procase.UUCP (Roger H. Scott) writes: >Andrew Koenig's "helper" functions [build()] don't solve the problem of >factoring out common *initialization*. For example, .... Again, an alternative approach to constructor helper methods is to introduce an intermediate helper class. C++ is designed such that introducing a helper class need not lead to an unreasonable cost. class Base { public: Base(int, double, char *, char *); }; class String { public: String(char *); }; class HelpDerive : public Base { public: HelpDerive() : Base(2,4.6,"foo","bar"), Mem1("aack"), Mem2("pfft") { } private: String Mem1, Mem2; }; class Derived : public HelpDerive { public: Derived() : myI(0), myJ(0) { } // [this example could be handled Derived(int i) : myI(i), myJ(0) { } // better via default args .... Derived(int i, int j) : myI(i), myJ(j) { } // .... ] private: int myI, myJ; };