Skip to content

Instantly share code, notes, and snippets.

@rpapallas
Created July 5, 2019 17:51
Show Gist options
  • Save rpapallas/bec9aeb75ee0cbe60e970e66498da1bd to your computer and use it in GitHub Desktop.
Save rpapallas/bec9aeb75ee0cbe60e970e66498da1bd to your computer and use it in GitHub Desktop.
C++ thread of a class overloaded method
class MyClass {
.
.
bool desiredOverloadedMethod() {
return true;
}
bool desiredOverloadedMethod(int a) {
if(a == 1)
return false;
return true;
}
};
MyClass objectInstance(someArgument);
// This points to the first method (desiredOverloadedMethod) without arguments.
bool (MyClass::*myFunc)() = &MyClass::desiredOverloadedMethod;
thread t1(myFunc, std::ref(objectInstance));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment