I'm trying to figure out the = operator overload. I want to have a string earliestShow; and iterate through the vector, find the earliest show and assign the show[i].getDate = earliestShow. Any ideas?
You're going to want a findEarliestShow() function. That function should return a reference to a show. This really belogs in a Shows class, but since you don't have one yet, this can either be a global function, or a friend function inside your Show class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
friend Show & findEarliestShow() .// Member of Show class
{ vector<Show>::iterator iter;
vector<Show>::iterator earliest;
if (shows.empty())
throw std::exception ("No shows in vector");
earliest = shows.begin();
for (iter=shows.begin(); iter=shows.end(); iter++)
{ if (shows[i].date < earliest->date) // Requires Date overload the < operator
earliest = iter;
}
return *iter;
}
bool Date::operator < (const Date & rhs) const
{ return (year < rhs.year && month < rhs.month day < rhs.day);
}
assign the show[i].getDate = earliestShow.
getDate is a function. You can't put that on the left side of an assignment.
edit: Provided a more compact form of Date::operator <.