the error I am given:
no matching function for call to ‘SimpleRecommender::getMovieId(std::string&)’
What is written in my header file(without my other functions):
class MyClass
{
template<class Iterator>
int getId(string Name);
};
What is written in my .cc file:
template<class Iterator>
double Recommender::generatePrediction(int userid, string Name){
int movieId=Recommender::getId(Name);
double avg=0;
for(Iterator current=ratings.begin();current!=ratings.end();current++){
if((*current).movieId==movieId){
avg+=(*current).rating;
avg/=2.0;
}
}
return avg;
}
template<class Iterator>
int Recommender::getMovieId(string movieName){
for(Iterator current=movies.begin();current!=movies.end();current++){
if((*current).getName().compare(movieName)==0)
return (*current).getId;
else{
cout<<"ERROR: movie not found"<<endl;
exit();
}
}
};
Note: Ratings is a vector
What would cause this error?
Shouldn’t there be a reference operator in:
like this?:
How do you call the function from your code?
Also, if you don’t change the value inside the function, you can consider using
const string &instead ofstringorstring &.