Home » Community » Newbie corner » CallbackN<> storing pointer to member function
CallbackN<> storing pointer to member function [message #56164] |
Tue, 02 February 2021 17:30  |
 |
Xemuth
Messages: 387 Registered: August 2018 Location: France
|
Senior Member |
|
|
It may seems odd, but I have this chunk of code :
class Module{
...
protected:
void RegisterFonction(Callback2<ValueMap&, Command&> cb, const String& commandName){
handlers.Add(ToLower(commandName),cb);
}
private:
ArrayMap<String, Callback2<ValueMap&, Command&>> handlers;
...
};
#define REGISTER(FonctionName) RegisterFonction((&CLASSNAME::FonctionName), #FonctionName);
class Info : public Module{
public:
typedef Info CLASSNAME;
Info(TheBot& _bot) : Module(_bot){
REGISTER(Uptime);
}
void Uptime(ValueMap& payload, Command& dispatched){
...
}
};
The Register macro is used to add the arrayMap some ptr to member function. Of course it don't compile :
error: no viable conversion from 'void (Upp::Info::*)(Upp::ValueMap &, Upp::Command &)' to 'Callback2<Upp::ValueMap &, Upp::Command &>' (aka 'CallbackN<Upp::ValueMap &, Upp::Command &>')
Is the thing I'm trying to do is possible ?
Thanks in advance
Best regard
[Updated on: Tue, 02 February 2021 17:33] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Mon Apr 28 13:34:05 CEST 2025
Total time taken to generate the page: 0.00440 seconds
|