From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: Calling Class Constructors and Destructors Date: Mon, 09 Feb 1998 19:10:21 -0500 Organization: Cornell University (http://www.cornell.edu/) Lines: 29 Sender: asu1 AT cornell DOT edu (Verified) Message-ID: <34DF9AED.486D449C@cornell.edu> References: <34df6b1d DOT 3108479 AT news DOT easynet DOT co DOT uk> NNTP-Posting-Host: cu-dialup-0922.cit.cornell.edu Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Geoffrey French wrote: > int main() > { > TC x, *y; > > x = TC(1); > y = new TC(1); > } > > I find that upon calling the constructor TC(long i) in the line 'x = > TC(1)' not only is the constructor called, but the destructor is > called straight afterwards (!), thus deleteing the reserved memory for > the variable a. However, in the line 'y = new TC(1)' only the > constructor is called. It seems that whenever you say 'c = > TClass(...)' the TClass destructor is called as well as the > constructor. by the time x = TC(1); has been executed, x has already been initialized using the default constructor. you can use: TC x(1); to use the alternate constructor. -- Sinan