Bonsoir!
Voici un petit code et le message du compilateur pour illustré mon problème.
J'ai déja essayé plusieur choses pour que le troisieme argument de "for_each" soit perçu comme il ce doit par ce dernier mais je n'ai pas encore trouvé:
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
 
#include <iostream>
#include <vector>
 
 
class B
{
    public:
    B();
    ~B();
    protected:
    void _print(int);
};
class A
{
    public:
    A();
    ~A();
    //void _affiche();
    void _modif();
    protected:
    B* m_pb;
    std::vector<int> m_list;
    //void _print(int);
};
int main(void)
{
//lorsque j'écrirai là, mon problème sera résolu!!
    return 0;
}
//definitions
A::A():m_pb(new B)
{
    for(int i=1;i!=10;i++){m_list.push_back(i);}
}
A::~A(){}
B::B(){}
B::~B(){}
/*void A::_affiche()
{
    for_each(m_list.begin(),m_list.end(),_print);
}
void A::_print(int i)
{
    std::cout<<"i: "<<i;
}*/
void A::_modif()
{
    for_each(m_list.begin(),m_list.end(),m_pb->_print);
}
void B::_print(int i)
{
    std::cout<<"i mod: "<<i+2;
}
Lorsque je "dé-commente" les autres lignes le problème semble identique:
/home/.../main.cc||In member function 'void A::_modif()'
/home/.../main.cc|48|erreur: argument of type 'void (B:(int)' does not match 'void (B::*)(int)'|
/usr/lib/gcc/x86_64-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algo.h||In function '_Function std::for_each(_InputIterator, _InputIterator, _Function) [with _InputIterator = __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, _Function = void (B::*)(int)]'
/home/.../main.cc|48|instantiated from here|
/usr/lib/gcc/x86_64-mandriva-linux-gnu/4.2.2/../../../../include/c++/4.2.2/bits/stl_algo.h|159|erreur: must use '.*' or '->*' to call pointer-to-member function in '__f (...)'|
||=== Build finished: 2 errors, 0 warnings ===|
Je signal au passage que j'utilise un pointeur "B* m_pb" pour aller chercher la fonction car il me faut un moyen pour identifier une classe B précise. Peut être cela peut-il être fait autrement?