Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!tut.cis.ohio-state.edu!mailrus!sharkey!mcf!mibte!gamma!thumper!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c++ Subject: Re: constructor calls constructor? Keywords: constructors, this Message-ID: <9396@alice.UUCP> Date: 26 May 89 23:07:07 GMT References: <601@rna.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 30 In article <601@rna.UUCP>, kc@rna.UUCP (Kaare Christian) writes: > Is there a way for one constructor to call another, simply to have > some chores performed, while avoiding real construction? Nope. Roundabout or not, the best way to do it is with helper functions. However, if you really insist, C++ 2.0 will have a way to say `construct an object of type T at location X," as follows: new (X) T (args); So by saying new (this) T (args); you will, in effect, be able to call one constructor from another. Having called this operator new, you'll need to define it: void* operator new(size_t,T* tp) { return tp; } and then you're in business. I said `if you really insist' because I think it's conceptually cleaner to use helper functions and it is probably worthwhile not to cut yourself off from older C++ implementations. -- --Andrew Koenig ark@europa.att.com