Skip to content

Instantly share code, notes, and snippets.

@FlyingJester
Created January 12, 2014 11:39
Show Gist options
  • Save FlyingJester/8383600 to your computer and use it in GitHub Desktop.
Save FlyingJester/8383600 to your computer and use it in GitHub Desktop.
A C++ function that calls any other function. As you may have guessed from its name, it's for a threading abstraction library.
#include <iostream>
using namespace std;
#include <functional>
#include <cstring>
void (*function1)(int , int);
template<typename R, typename ...A>int CreateThread(R(*ThreadFunc)(A...), A ...args){
std::function<R(A...)>func(ThreadFunc);
ThreadFunc(std::forward<A> (args)...);
}
void function2(int i, int e){
cout << i << e << endl;
}
int main()
{
int a = 100;
int b = 99;
void *ap = &a;
const void *bp = &b;
CreateThread(&memcpy, ap, bp, (size_t)4);
function1 = function2;
cout << "Hello World" << endl;
CreateThread(&function2, 10, a);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment