Kai-Uwe Bux wrote:
[snip]
However, something like
std::stringstream i_str = some_cond ? str_stream_1 : str_stream_2;
is an entirely different matter (note the absence of &). In this case, a
copy constructor is invoked which for streams, I think, is required to
fail.
I understand that. Consider:
#include <sstream>
#include <iostream>
class fail : public std::stringstream {
public:
fail() : std::stringstream() {}
fail(const fail& rhs) : std::stringstream(std::ios::in |
std::ios:
ut) {}
};
int main() {
try {
throw fail();
} catch(fail& e) {
}
}
I have provided a perfectly acceptable, although, admittedly not great,
copy constructor, yet VC8 fails compilation with the following error:
C:\Program Files\Microsoft Visual Studio 8\VC\include\sstream(513) :
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access
private member declared in class 'std::basic_ios<_Elem,_Traits>'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
C:\Program Files\Microsoft Visual Studio 8\VC\include\ios(151)
: see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
with
[
_Elem=char,
_Traits=std::char_traits<char>
]
This diagnostic occurred in the compiler generated function
'std::basic_stringstream<_Elem,_Traits,_Alloc>::basic_stringstream(const
std::basic_stringstream<_Elem,_Traits,_Alloc> &)'
with
[
_Elem=char,
_Traits=std::char_traits<char>,
_Alloc=std::allocator<char>
]
<snip similar errors cascaded into istream and ostream>
It has attempted to create a copy constructor for the stringstream base,
even though one is not required (I have provided a copy constructor for
fail, that does not require a copy constructor for the base).