Nick Keighley writes:
Hi,
I'm having problems with stringstream, specifically it won't
compile with Visual C++ 2008 Express. This may be a problem with
CPPX, in which case I'll go elsewhere (suggestions?). But is
there an obvious bug with this code?
#include <iostream>
#include <sstream>
class Lexer
{
public:
explicit Lexer (std::istream&);
~Lexer ();
private:
std::istream stream_;
};
Lexer::Lexer (std::istream& in_stream):
stream_(in_stream)
std::istream is not copyable. std::istream does not define a copy
constructor, or an assignment operator.
The diagnostic is:
c:\program files\microsoft visual studio
9.0\vc\include\istream(846) : error C2248:
'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
1>
it sems to be claiming a bug in istream, which doesn't sound
good...
I see no evidence of a bug. This is just one possible
manifestation of an undefined copy constructor or assignment
operator.
Redefining your class member as a reference, "std::istream
&stream_;" should work, but keep in mind that your
std::istringstream object you're using to initialize this
reference must exist as your Lexer object exists, in order for
this reference to remain valid.