Given
class Fred {
public:
friend std::ostream& operator<< (std::ostream& o, const Fred& fred);
...
private:
int i_; // Just for illustration
};
std::ostream& operator<< (std::ostream& o, const Fred& fred)
{
return o << fred.i_;
}
from the FAQ, what is wrong with the following class declaration?
(How TLSFile is implemented isn't really germane here)
class
TLSFileStream : public TLSFile
{
private:
std::string buf;
public:
friend std::ostringstr eam &operator<< (std::ostringst ream &ss, TLSFileStream &lsf)
{return(ss << lsf.AsString()) ;} // I get a warning about
// references initialized with
// ostream - huh??
WriteStr( std::str s );
};
template <class T>
TLSFileStream& operator<< (TLSFileStream& lsf, const T& t)
{
std::ostringstr eam ss;
ss << t; // trying to use << operator above, says that << isn't
// implemented for TLSFile - huh?? ;(
lsf.WriteStr( ss.str() );
return lsf;
};
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
class Fred {
public:
friend std::ostream& operator<< (std::ostream& o, const Fred& fred);
...
private:
int i_; // Just for illustration
};
std::ostream& operator<< (std::ostream& o, const Fred& fred)
{
return o << fred.i_;
}
from the FAQ, what is wrong with the following class declaration?
(How TLSFile is implemented isn't really germane here)
class
TLSFileStream : public TLSFile
{
private:
std::string buf;
public:
friend std::ostringstr eam &operator<< (std::ostringst ream &ss, TLSFileStream &lsf)
{return(ss << lsf.AsString()) ;} // I get a warning about
// references initialized with
// ostream - huh??
WriteStr( std::str s );
};
template <class T>
TLSFileStream& operator<< (TLSFileStream& lsf, const T& t)
{
std::ostringstr eam ss;
ss << t; // trying to use << operator above, says that << isn't
// implemented for TLSFile - huh?? ;(
lsf.WriteStr( ss.str() );
return lsf;
};
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Comment