delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/19/08:15:58

From: beaver AT reksoft DOT ru (Slava Jarki)
Newsgroups: gnu.gcc.help,comp.os.os2.programmer.misc,comp.os.msdos.djgpp
Subject: Re: C++ constructor problem solved!! Read how, it might come in useful in your future programs!
Date: 19 Jan 1998 07:45:50 GMT
Organization: REKSoft
Lines: 30
Message-ID: <JgXSRD37O5mZ-pn2-GDBMovdtZi5F@beaver_pc.reksoft.ru>
References: <bWLoegW7sFse-pn2-bxyqvlUyVUyY AT localhost> <34C2817A DOT 5547BE86 AT alcyone DOT com>
NNTP-Posting-Host: 194.8.172.152
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Sun, 18 Jan 1998 22:26:02, Erik Max Francis <max AT alcyone DOT com> 
wrote:

> Erik wrote:
>

> Explicitly calling constructors is dangerous.  Here what's _really_
> happening is that the fstream is being constructed with the default
> constructor, and _then_ you're explicitly calling a nondefault
> constructor.  That is, it's functionally precisely the same thing as:
>
>     File::File(...):
>         fstream()
>     {
>         ((fstream *) this)->fstream(...);
>         ...
>     }
>
> This is unwise and can have unwanted side effects, particularly if
> memory is being allocated in the default constructor (because then it
> will get allocated twice).
>

Ok I am agree, but constructor not allocate memory for object. It
adjust VMT.


Best luck.
Slava Jarki.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019