Newsgroups: comp.os.msdos.djgpp,comp.os.os2.programmer.misc,gnu.gcc.help Subject: Re: C++ problem -- Over 30 people were unable to help me, can you?! From: frenchc AT cadvision DOT com (Calvin French) References: MIME-Version: 1.0 Content-Type: Text/Plain; charset=US-ASCII NNTP-Posting-Host: ts3ip104.cadvision.com Message-ID: <34c01654.0@news.cadvision.com> Date: 17 Jan 98 02:24:20 GMT Organization: CADVision Development Corporation (http://www.cadvision.com/) Lines: 49 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk >when fstream() is called from the constructor initialization.) Does >anyone have any idea how this problem could be solved? I understand your problem. I think, basically there are two things you could try. The first I would try (well actually maybe I'd cut right to the second because I'm an impatient little hack) is to call the constructor with File::fstream(), maybe that alternative will do what you want. I've had so much headaches with constructors, I know what it is like and as a result I've become a bit jaded as it were. So much so that I might be likely to just do this: class File { fstream* f; public: File( ...etc... ) { ...etc... }; virtual ~File() { ...etc...; delete f; }; ...etc... }; There is another less obvious advantage to this. Consider how flexible the following type of wrapper-class is: class File { fstream* f; bool persistant; public: File( ...etc... ) : persistant(0) { ...etc... }; File( fstream* F ) : f(F), persistant(1) { ...etc... }; virtual ~File() { ...etc...; if( !persistant ) delete f; }; ...etc... }; Hoping you don't mind the excessive ...etc...'s, this little thing can be quite useful for when you already have an fstream (for example, in old code, or rather, old code which calls existing functions taking an fstream as a parameter, then when you want to change the function called, you can use your super-enhanced fstream wrapper without changing the old code: makes sense, no?) Oh! Then there's this, which is a little secret weapon I have for when I'm supermad at construction in C++, but I started to type it in then realized it wasn't worth it. Hehehehehe... - Calvin -