Alf P. Steinbach wrote:
Well, first fix the code, then try again.
I was writing it from my head.
But I assume it was disrespectful to post non-working code..
Here's the more proper one:
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
struct Node {
int val;
int index;
};
struct A
{
std::vector<Node*> Nodes;
A() {};
bool EqIndex(const Node* ptr, int idx) const
{
return (ptr->index == idx);
};
int foo()
{
std::find_if(Nodes.begin(), Nodes.end(),
std::bind2nd(&A::EqIndex, 5));
return 0;
};
};
int main(int argc, char* argv[])
{
A a;
a.foo();
return 0;
}
The problem is in the std::find_if(...bind2nd...).
My guess is that it assumes that given type is only class/struct.
I've also tried to use std::mem_fun - no effect.
Do I have to write a functor to use such functionality?
non-static member function and won't work directly if you insist.
std::ptr_fun.
A: Because it messes up the order in which people normally read text.
A: Top-posting.