delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/01/18/13:00:36

From: NOSPAMsl AT psycode DOT com (Gili)
Newsgroups: comp.os.msdos.djgpp,gnu.gcc.help,comp.os.os2.programmer.misc
Subject: C++ constructor problem solved!! Read how, it might come in useful in your future programs!
Date: 18 Jan 1998 17:37:22 GMT
Organization: Generation.NET
Lines: 30
Message-ID: <bWLoegW7sFse-pn2-bxyqvlUyVUyY@localhost>
Reply-To: NOSPAMsl AT psycode DOT com
NNTP-Posting-Host: portC59.Generation.NET
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


Here is a quick review of the problem:

	File() is a class which inherites publicly from fstream() (in other 
words, "class File : public fstream")
We want to be able to call the base constructor of fstream() when the 
constructor of File() is called. We know we can do this in this 
fashion:

File::File(<parameters>):
fstream(<parameters>)
{
  <body goes here>
}

	However, we wanted to be able to call the base constructor from the 
body of the File() constructor. This would allow more flexibility, 
mainly allowing you to use exception-handling for this call. The 
solution took me 2 days to find, but here it is:

File::File(<parameters>)
{
  ((fstream*)this)->fstream(<parameters>);
  <body goes here>
}

	Many thanks to Peter Nielsen and Calvin French for their help...

Gili

- Raw text -


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