Created
January 12, 2014 11:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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