Voici un petit code test:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

class Foo
{
public:
	Foo(int val) : m_val(val) {}
	bool operator==(const Foo & foo) const { return (foo.m_val == m_val); }

private:
	int m_val;
};

bool same_as(const Foo & val1, const Foo & val2)
{
	return (val1 == val2);
}

int main()
{
    vector<Foo> vf;
    vf.push_back(Foo(1));
    vf.push_back(Foo(2));
    vf.push_back(Foo(3));
    vf.push_back(Foo(4));
    vf.push_back(Foo(5));
    typedef vector<Foo>::const_iterator VI;
    VI p = find_if(vf.begin(), vf.end(), bind2nd(ptr_fun(same_as), Foo(3)));
    cout << ((p != vf.end()) ? "OUI" : "NON") << endl;
    return 0;
}
Si dans ma fonction same_as, j'utilise des références alors, ça ne marche pas, par contre, si j'en ai pas alors ça marche. Comment faire pour que ça marche avec les références?