0

I would like to create a callback for this function prototype : Timer_Install(int, void (*)(), int);

So far, I tried to use a lambda function with std=c++11

auto receive = [this](){receptMessage();}; // pointer on this->receptMessage();
Timer_Install(0, receive, 1);

Wich result in the following error :

error : canot convert 'Obj::method::' to 'void(*)()'

I have also tried various things like :

void (*ptrReception)();
ptrReception = this->receptMessage;
Timer_Instal(0, ptrReception, 1);

error : cannot convert 'Obj::method' from type 'void(Obj::)()' to type 'void(*)()'

Is there anyway to get this working ?

AnonBird
  • 570
  • 13
  • 27
  • 3
    Capturing lamdas cannot be converted into function pointers. There must be a duplicate somewhere.... – Rakete1111 Sep 11 '16 at 12:14
  • There must be hundreds of duplicates of this question by now. – Kerrek SB Sep 11 '16 at 12:14
  • Do your timer-API allow you to pass some kind of user-data? Perhaps a pointer? Then you can use that pointer for the object instance (i.e. `this`) and use a static member function that takes the pointer and call the real function in the object. Otherwise it's really not possible, what you're trying to do. – Some programmer dude Sep 11 '16 at 12:16
  • @JoachimPileborg No, there is no way to pass user-data. – AnonBird Sep 11 '16 at 12:18
  • Then you have to think of another way. By the way, what does the two `int` arguments mean? Can't they be used in some way to map to an object? Maybe you should try and find some other timer API that is more compatible with C++ code? – Some programmer dude Sep 11 '16 at 12:21
  • @Rakete1111 This is more a question about _what i have tried so far_ than a real question about how to convert lambda to function pointer – AnonBird Sep 11 '16 at 12:21
  • @JoachimPileborg Not possible, as I'm already using a sycall. – AnonBird Sep 11 '16 at 12:22
  • @Xavier59 Yeah, I would've used another question as duplicate too, but I couldn't find one. – Rakete1111 Sep 11 '16 at 12:23
  • @Rakete1111 So maybe it is not one .... – AnonBird Sep 11 '16 at 12:31

0 Answers0