0

次の宣言があります。

friend ostream& operator<<(ostream&,const List&);

そして、私は次の定義を持っています:

ostream& operator<<(ostream& out,const List& item) {
    vector<List::Employee>::const_iterator It;
    for (It=item.employees.begin();It!=item.employees.end();It++) {}
}

Employee は私自身の構造体であり、employees はクラス List の Employee のプライベート ベクトルです。コンパイラは私に次のエラーを与えます:

std::vector<List::Employee,std::allocator<List::Employee>> List::employees is private

それを解決する方法はありますか?

4

1 に答える 1

0

フレンド宣言は List クラス定義内にある必要があります。

class List{
    ...
    friend ostream& operator<<(ostream&,const List&);
};
于 2012-12-03T06:03:09.403 に答える