代码如下:
inline ostream operator<<(ostream& os, const istring s)
{
return os<<string(s.c_str(), s.length());
}
编译它出现:std::ios_base::ios_base(const std::ios_base&)' is private 错误。
这是因为流作为参数传递时必须通过引用传递,所以正确的代码是
inline ostream& operator<<(ostream& os, const istring s)
{
return os<<string(s.c_str(), s.length());
}