for_each et appel fonction membre
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| #include <iostream>
#include <vector>
#include <algorithm>
class A
{
public:
void func1(const std::vector<int> &v)
{std::for_each(v.begin(), v.end(), func2); }
void func2(int val) { /* Traitement */ }
};
int main()
{
A a;
std::vector<int> v;
v.push_back(7);
v.push_back(3);
v.push_back(28);
a.func1(v);
return 0;
} |
J'aimerais faire appel à func2, mais ça ne marche pas. Normal, car ce n'est pas une fonction traditionnelle, mais une fonction membre.
J'essaie de faire appel à mem_func_ref, mais ça ne marche pas non plus :?