Mail Archives: djgpp/1998/01/19/21:30:53
On Sun, 18 Jan 1998 22:26:02, Erik Max Francis <max AT alcyone DOT com>
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(...);
> ...
> }
I found a second (and perhaps better) way of doing this. Now I use
"this->fstream.fstream(<parameters>".
> class File
> {
> public:
> fstream *fs;
>
> File(...);
> ...
> };
>
> File::File(...)
> {
> fs = new fstream(...);
> ...
> }
>
This is unacceptable because I wanted to publicly inherite fstream().
I could use delegation like this but then I won't be inheriting the
methods and variables of fstream().. Once again, I think
"this->fstream.fstream()" is a good solution.
Gili
- Raw text -