unresolved overloaded function type - problem

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);
}
Last edited on
The compiler points out name left but you did not show what is the left.
I have tested your code and it is compiled

namespace Fruits
{
struct mystruct;

void eval();
bool Compare(mystruct apple,mystruct orange);

}

struct Fruits::mystruct{
double weight;
};

bool Fruits::Compare(mystruct apple,mystruct orange){
return apple.weight < orange.weight;
}

void Fruits::eval(){
std::vector<mystruct> fruits;
mystruct apple, orange;
apple.weight = 3.0;fruits.push_back(apple);
orange.weight = 2.0;fruits.push_back(orange);
std::vector<mystruct>::iterator heaviest =
max_element(fruits.begin(),fruits.end(),Compare);
}

Last edited on
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.
Topic archived. No new replies allowed.