我有一个处理音乐专辑的Class
。 artists
和albums
是strings
。它还有一个名为contents
的曲目集合(vector
)。每个曲目有一个title
和一个duration
。C++ ostream << Operator
这是我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类缺少的东西?
'Album :: getContents()'返回什么? – juanchopanza
getContents返回什么? –