vendredi 29 septembre 2017

initialize class A static std::map

I have a static std::map declared static in class A (A.hpp) :

typedef bool (*fct_pointer_t)(uint8 *msg, void *other);
typedef std::map<std::string, fct_pointer_t> map_string_to_fct_t;
class A {
     static map_string_to_fct_t str_to_fct;
}

I need to initialize this A static std::map with pointers to class B functions. This is done in B.cpp file:

map_string_to_fct_t A::str_to_fct = {
    {"string1", &B::fct1},
    {"string2", &B::fct2},
}
B::fct1(uint8* msg, void*){
...
}
B::fct2(uint8* msg, void*){
...
}

In order for A static member to have access to member functions of B, I declare A friend of B as follows in B.hpp file:

class B {
    friend class A;
    fct1(...);
    fct2(...);
}

Now, why do I get this error at compilation ?

error: could not convert [...] from 'brace-enclosed initializer list' to 'map_string_to_fct_t {aka std::map, bool (*)(uint8*, void*)>}

Thanks for your help.

Aucun commentaire:

Enregistrer un commentaire