Hi. I try to find maximum element of a vector. But I get error message: cplxOp.cpp:18:52: error: no matching function for call to ‘max_element(std::vector<Fruits::mystruct>::iterator, std::vector<Fruits::mystruct>::iterator, <unresolved overloaded function type>)’
I tried to help my compiler by heaviest = max_element(fruits.begin(), fruits.end(),
static_cast<bool(*)(CvPoint&,CvPoint&)>(left) ); But, it didn't work. Any ideas?
//cplxOp.cpp
#include <algorithm>
#include <vector>
#include "cplxOp.h"
using namespace std;
struct Fruits::mystruct{
double weight;
};
bool Fruits::Compare(mystruct apple,mystruct orange){
return apple.weight < orange.weight;
}
void Fruits::eval(){
vector<mystruct> fruits;
mystruct apple, orange;
apple.weight = 3.0;fruits.push_back(apple);
orange.weight = 2.0;fruits.push_back(orange);
vector<mystruct>::iterator heaviest =
max_element(fruits.begin(),fruits.end(),Compare);
}
Thank you very much. Sorry, that static_cast<bool(*)(CvPoint&,CvPoint&)>(left) );
was a little bit confusing :-) It was a solution for similar kind
of problem. I found it from the google and I accidentally copied
that from the webpage, not from my code.