为什么我的代码出错:
ostream operator<<(ostream flux, Perso const A)
{
A.O_Show(flux);
return flux;
}
error: use of deleted function 'std::basic_ostream<char>::basic_ostream(const std::basic_ostream<char>&)'|
没有错误:
ostream& operator<<(ostream& flux, Perso& const A)
{
A.O_Show(flux);
return flux;
}
你能解释一下有什么区别吗?
答案 0 :(得分:2)
至于你的代码
ostream operator<<(ostream flux, Perso const A) {
A.O_Show(flux);
return flux;
}
您无法将std::ostream
复制为返回值(c++11标准之前,甚至第一位protected
),只需将代码更改为
ostream& operator<<(ostream& flux, Perso& const A) {
// ^
A.O_Show(flux);
return flux;
}