我已经尝试了很多事情来尝试让它工作,但没有任何效果,我真的很困惑我必须做些什么来解决这个问题。
std::ostream& operator <<(std::ostream& os, const Book& b){
os<<b.getTitle()<<", "<<b.getYear();
return os;
}
friend std::ostream& operator<<(std::ostream&, const Book&);
我不断收到这个错误
Book.cc: In function 'std::ostream& operator<<(std::ostream&, const Book&)':
Book.cc:45: error: no match for 'operator<<' in 'std::operator<< [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](((std::basic_ostream<char, std::char_traits<char> >&)((std::basic_ostream<char, std::char_traits<char> >*)os)), ((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >&)((const std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)(& Book::getTitle() const())))) << ", "'
Book.cc:44: note: candidates are: std::ostream& operator<<(std::ostream&, const Book&)
我真的很困惑如何做到这一点。谢谢您的帮助。