I defined a class Movie
. And that class has a
static set<Movie> movies;
I also have a static member function:
static Movie& find_by_title(string);
I'm returning a reference, because I want to modify the movie once I find it (I want to rate it). So, in the implementation I have
Movie& Movie::find_by_title(string title) {
set<Movie>::iterator it;
for (it = movies.begin(); it != movies.end(); ++it)
if (it->title == title) return *it;
}
But it returns an error, because *it
has a type of const Movie
(and the function returns Movie&
). But then how to get that element in a way I can change it? A pointer would also be ok, anything that would make it possible to change the element afterwards.
movies.find(*it)
also returns an iterator to a const Movie
, so it also doesn't work when I try to return *(movies.find(*it))
.