C
Christopher Benson-Manica
Given
class Fred {
public:
friend std:stream& operator<< (std:stream& o, const Fred& fred);
...
private:
int i_; // Just for illustration
};
std:stream& operator<< (std:stream& 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:stringstream &operator<< (std:stringstream &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:stringstream ss;
ss << t; // trying to use << operator above, says that << isn't
// implemented for TLSFile - huh?? ;(
lsf.WriteStr( ss.str() );
return lsf;
};
class Fred {
public:
friend std:stream& operator<< (std:stream& o, const Fred& fred);
...
private:
int i_; // Just for illustration
};
std:stream& operator<< (std:stream& 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:stringstream &operator<< (std:stringstream &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:stringstream ss;
ss << t; // trying to use << operator above, says that << isn't
// implemented for TLSFile - huh?? ;(
lsf.WriteStr( ss.str() );
return lsf;
};