我有一个运算符重载的类,如下所示:
friend ostream operator<< (ostream &stream, const Item &item){
stream << item.title << " - " << item.format << " (Loaned to " << item.name << ") on " << item.date;
return stream;
}
Run Code Online (Sandbox Code Playgroud)
我的程序无法编译,并给我以下错误:
error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' : cannot access private member declared in class 'std::basic_ios<_Elem,_Traits>'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> c:\program files (x86)\microsoft visual studio 8\vc\include\ios(151) : see declaration of 'std::basic_ios<_Elem,_Traits>::basic_ios'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> This diagnostic occurred in the compiler generated function 'std::basic_ostream<_Elem,_Traits>::basic_ostream(const std::basic_ostream<_Elem,_Traits> &)'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?为什么说私人会员不能访问,我很困惑.
你必须返回一个参考.
friend ostream& operator<< (ostream &stream, const Item &item)
// ^
Run Code Online (Sandbox Code Playgroud)
流的复制构造函数被删除/私有.
| 归档时间: |
|
| 查看次数: |
48 次 |
| 最近记录: |