operator << 对象向量的重载

operator << overloading for vector of objects

各位。

我有一个名为 "Card" 和 "CardDeck" 的 class,其中第二个是矢量,其中包含许多第一张 class 的卡片。

我的 << 重载是这样的:

istream& operator<<(ostream& os, Card& card) {
    string str;
    if(cardValueCorrect(card._value)){
        str += to_string(card._value);
    } else {
        str += card._identier;
    }
    str += suitToChar(card._suit);
    return os << str;

而且我认为应该没问题,至少编译器不会抱怨这一点。当我想在我的 CardDeck 中重载 << 以便打印所有卡片时,问题就开始了。

CardDeck << overloading seems like that: 
ostream& operator<<(ostream& os, CardDeck& odeck){
    for(const Card cur_card: odeck._Deck){
        os << cur_card << ' ';
    }
    return os;
}

它抱怨访问卡的私有字段以及:

invalid initialization of reference of type 'std::istream& {aka std::basic_istream<char>&}' from expression of type 'std::basic_ostream<char>'

然后是其他非常奇怪的东西(关于第一个运算符重载中的 每一行 ):

within this context

编辑

istream 到 ostream 已修复。

这是一个问题。现在我看到 162 个警告 "info" 关于 CardDeck 运算符重载,它告诉我我正在 进入 CardDeck 的私有字段(向量在那里)。

天气:

`invalid initialization of non-const reference of type 'CardDeck&' from an rvalue of type no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'const Card')` 

和很多这样的重复模式 "info"(蚀):

'const Card' is not derived from 'const std::extreme_value_distribution<_RealType>'

替换

istream& operator<<(ostream& os, Card& card)

ostream& operator<<(ostream& os, Card& card)