Newsgroups: comp.os.os2.programmer.misc,gnu.gcc.help,comp.os.msdos.djgpp From: idanan AT ibm DOT net Subject: Re: C++ problem -- Over 30 people were unable to help me, can you?! Reply-To: idanan AT ibm DOT net References: NNTP-Posting-Host: 129.37.161.124 Message-ID: <34c233a4.0@news1.ibm.net> Date: 18 Jan 98 16:53:56 GMT Organization: IBM.NET Lines: 47 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk In , bjorn AT algonet DOT se (Bjorn Fahller) writes: >On Sat, 17 Jan 1998 00:51:46, NOSPAMsl AT psycode DOT com (Gili) wrote: > >> Hi, >> >> I created a class called File() which inherites fstream() publically >> (i.e. class File : public fstream) >> I'd like to call fstream()'s constructor whenever File()'s constructor >> is called. However, I have run into a major problem. >> I can call the constructor in this way: >> " >> File::File(const char* name, int mode, int prot): >> fstream(name, mode, prot) >> { >> >> } >> " >> >> However, I'd like to use exception-handling and that isn't possible >> in the constructor initialization. What I'd like to do is to be able >> to call the fstream() constructor from the body of File()'s >> constructor. This would allow me to use exception-handling... However, >> simply calling fstream() in the body seems to make C++ think I'm >> creating an fstream() variable instead of calling the constructor. >> Also, when I try using ::fstream() to call the constructor, the call >> *seems* to work but my file does not open correctly (which it does >> when fstream() is called from the constructor initialization.) Does >> anyone have any idea how this problem could be solved? [CUT] C++ has a way of doing this. The proper syntax is: File::File(const char* name, int mode, int prot) try : fstream(name, mode, prot) { } catch () { } - Itai idanan AT ibm DOT net