Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » CallbackN<> storing pointer to member function
CallbackN<> storing pointer to member function [message #56164] Tue, 02 February 2021 17:30 Go to next message
Xemuth is currently offline  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

Re: CallbackN<> storing pointer to member function [message #56165 is a reply to message #56164] Tue, 02 February 2021 17:44 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
a Solution would be to change macro to :
#define REGISTER(FonctionName) RegisterFonction([&](ValueMap& payload, Command& dispatched){FonctionName(payload,dispatched);}, #FonctionName);

and change callbackN to Event<> but I don't like a lot this solution
Previous Topic: WebImage example not working
Next Topic: Get volume name of shares ...
Goto Forum:
  


Current Time: Wed Apr 24 01:57:55 CEST 2024

Total time taken to generate the page: 0.02769 seconds