Reputation: 119
I have a compilation error: "no matching function for call to find(std::_List_iterator<Process>, std::_List_iterator<Process>, Process&)
" in my c++ program.
The mfqueue
class looks like:
MFQueue::MFQueue() {
list<Process> queue;
vector<int> ran;
int time_quantum = 0;
int run_for = 0;
}
MFQueue::MFQueue(int quantum) {
list<Process> queue;
vector<int> ran;
int time_quantum = quantum;
int run_for = 0;
}
"Process" is one of my class
bool MFQueue::contains(Process p) {
list<Process>::iterator itr = find(queue.begin(), queue.end(), p);
return (p == *itr);;
}
Does anyone know how to fix this problem? Thanks in advance!
Upvotes: 1
Views: 1665
Reputation: 45410
You need to overload operator==
for std::find
algorithm, assume you want to compare id of Process
say:
bool operator==(const Process &lhs, const Process& rhs)
{
return lhs.id== rhs.id;
}
now, you can get it working
#include <algorithm>
std::list<Process>::iterator itr = std::find(queue.begin(), queue.end(), p);
Upvotes: 1
Reputation: 10613
Why are you declaring list<Process> queue;
in the constructors not using them?
Upvotes: 0