Assume all includes are defined, please go through the code structure defined below.
std::unordered_map<std::string, void*> callbackReg;
class A
{
public:
void foo(int a)
{
//impl
}
void foo(int a, int b)
{
//impl
}
void foo(int a, double d)
{
//impl
}
};
template<class Instance , typename Function>
void register_func(Instance& obj, Function func)
{
/* have to store function name as the key and
- pointer to raw member function pointer as the value,
- in callbackReg Map */
// ---> Point B
}
int main(int argc, const char * argv[])
{
A a;
register_evt(a, &A::foo); //---> point A
system("Pause");
}
Problems and Discussions
- @
Point A
how to resolve function name scope resolution issue which means how to call a overloaded function/pointer to such function ? without inline static cast since it makes bit ugly and messy. - @
Point B
assume we have fixed overload name resolutuin issue and now we have to store member funtion name and its pointer value incallbackReg
map.
I know may this could bad cumbersome approach but, is this feasible in C++? or else is there any way to store raw memeber funtion pointers
with some other key-value in order to use them as callbacks
.Since at debug
time,debugger already knows what is the function name passed as register_func
template fucntion argument. Please look at the image attached.
-
Therefore,simply, how can we implement callback
register
/unregister
scenario using only raw member/non-member function pointers?
Aucun commentaire:
Enregistrer un commentaire