I’ve tried many things to try and get this to work but nothing works and im really confused at what i have to do to fix this.
std::ostream& operator <<(std::ostream& os, const Book& b){
os<<b.getTitle()<<", "<<b.getYear();
return os;
}
friend std::ostream& operator<<(std::ostream&, const Book&);
and i keep getting this error
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&)
I’m really stumped at how to do this.
Thanks for the help.
It’s hard to tell without seeing Book, but this works [code]:
Note that you don’t need to use
friendunlessoperator<<needs to access non-public data or functions. How do you declaregetTitle()?