【发布时间】:2018-04-10 16:36:42
【问题描述】:
我目前正在使用 c++11,我正在开发一个朋友函数来打印出某事,但在调用打印函数之前,我需要调用类内部的一个成员函数来访问和序列化这两个数据成员。我在修改 ostream 对象时遇到问题。 代码如下:
friend ostream& operator<<(ostream& os, const Card& c) {
c.serialize(os);
return os;}
void NumberCard:: serialize(ostream& os) const
{
Color c=this->getColor();
switch(c){
case Color::red: os=(os<<"R"<<this->getPoint());break;
case Color::yellow: os=(os<<"Y"<<this->getPoint());break;
case Color::blue: os=(os<<"B"<<this->getPoint());break;
case Color::green: os=(os<<"G"<<this->getPoint());break;
default:break;}}
我当前的方法不起作用,错误是:
use of deleted function 'std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator=(const std::basic_ostream<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]'
如果有人能给我一些建议,将不胜感激。
【问题讨论】: