这是我的代码(我只写了本质),我得到了这个:
错误:与“operator
class Mobil {
public:
void print() const;
int getNumber() const;
double getData() const;
friend ostream& operator <<(ostream&, const Mobil&);
};
ostream& operator<<(ostream& out, const Mobil& mobil) {
out << mobil.print() << endl;
return out;
}
问题是什么?
问题是这一行:out << mobil.print() << endl;
. Your print()
方法不返回任何内容(类型为void
),所以无法发送到ostream
.
为了解决这个问题,你的print()
方法应该返回您想要以支持的类型之一打印输出的任何内容ostream
你可以在其中找到参考 https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt2.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)