Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- template<typename F, typename... args, typename R>
- static R unsafe_c_callback(void* thisptr,args... a) {
- return (*((F*)thisptr))(a...);
- }
- template<typename F, typename... args, typename R>
- static void* C(const F& callback, R(*&fptr)(void*,args...)) {
- fptr = unsafe_c_callback<F,args...>;
- return (void*)&callback;
- }
- int main(int argc, char** argv) {
- auto bot = [=](const char* txt){
- printf("%s\n",txt);
- return 5;
- };
- int(*fptr)(void*,const char*);
- void* thisptr = C(bot,fptr);
- int rval = fptr(thisptr,"Lambda text");
- printf("%i\n",rval);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement