#include <cctype>
#include <deque>
#include <iostream>
#include <string>
#include <vector>
#include <iomanip>
#include <list>
#include <limits>
class Song {
friend std::ostream &os(std::ostream &os, const Song &s);
std::string name;
std::string artist;
int rating;
public:
Song() = default;
Song(std::string name, std::string artist, int rating)
: name{name}, artist{artist}, rating{rating} {}
std::string get_name() const {
return name;
}
std::string get_artist() const {
return artist;
}
int get_rating() const {
return rating;
}
bool operator<(const Song &rhs) const {
return this->name < rhs.name;
}
bool operator==(const Song &rhs) const {
return this->name == rhs.name;
}
};
std::ostream &operator<<(std::ostream &os, const Song &s){
os << std::setw(20) << std::left << s.name
<< std::setw(30) << std::left << s.artist
<< std::setw(2) << std::left << s.rating;
return os;
}
I am getting the error Song::name is private within this context, but I did not make it private. The std::stream &operator above me with the formatted output is the one I am having trouble with.
Aucun commentaire:
Enregistrer un commentaire