Mail Archives: djgpp/1998/01/16/21:30:25
<snip>
>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 -
- Raw text -