This is the mail archive of the libstdc++@sourceware.cygnus.com mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

fstream() constructor?


Hi,
  A colleague has written a bit of code which has in effect:

#include <fstream>

class x {
public:
  fstream s;

  x() {};

  void o(char* n);
};

void x::o(char* n) {
  s.open(n,ios::in);
}

(In another place he opens it for output instead).

While this works in Visual C++, and he has found an example in Lippman
showing that should work, Gcc generates the following error:

c++ -shared  -c -I/usr/local/newstdc++/include/g++-v3 t.cpp
/usr/local/newstdc++/include/g++-v3/bits/std_fstream.h: In method
`basic_fstream<char,char_traits<char> >::basic_fstream()':
t.cpp:7:   instantiated from here
/usr/local/newstdc++/include/g++-v3/bits/std_fstream.h:328: no matching
function for call to `basic_iostream<char,char_traits<char>
>::basic_iostream ()'
/usr/local/newstdc++/include/g++-v3/bits/std_istream.h:744: candidates
are: basic_iostream<char,char_traits<char>
>::basic_iostream(basic_streambuf<char,char_traits<char> > *)
/usr/local/newstdc++/include/g++-v3/bits/std_iosfwd.h:65:
basic_iostream<char,char_traits<char> >::basic_iostream(const
basic_iostream<char,char_traits<char> > &)

So it looks like there is no empty constructor for fstream; this code
works fine for an ifstream or an ofstream, but not for the plain fstream.

Should this work?

(This is with gcc-2.95.2 release and libstdc++-2.90.6)

Dave
/------------------------------------------------------------------\
| Dr. David Alan Gilbert | Work:dg@px.uk.com +44-161-286-2000 Ex258|
| -------- G7FHJ --------|---------------------------------------- |
| Home: dave@treblig.org   http://www.treblig.clara.net            |
\------------------------------------------------------------------/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]