我有一个Class处理音乐专辑的。artists和albums是strings。_ 它还有一个名为 ( vector) 的曲目集合contents。每个轨道都有一个title和一个duration。
这是我的ostream <<:
ostream& operator<<(ostream& ostr, const Album& a){
ostr << "Album: " << a.getAlbumTitle() << ", ";
ostr << "Artist: " << a.getArtistName() << ", ";
ostr << "Contents: " << a.getContents() << ". "; //error thrown here
return ostr;
}
<<旁边的下划线a.getContents()表示:"Error: no operator "<<" matches these operands.
我错过了什么或做错了什么?你不能用这种方式使用向量吗?或者也许是我在 Track 课上缺少的东西?