我有一個處理音樂專輯的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返回什麼? –