-
Notifications
You must be signed in to change notification settings - Fork 223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to have a member method as the executed function? #14
Comments
Hello, Yes, its actually pretty simple. Let's say this is your class: class ClassName
{
private:
int one;
public:
ClassName()
: one(1)
{}
int AddOne(const int b)
{
return one + b;
}
}; Then, you have to do this: ClassName classInstance;
// Creates a copy of classInstace, use std::ref(classInstance) to force pass by ref
auto function = std::bind(&ClassName::AddOne, classInstance, 3);
auto future = pool.submit(function);
// Get result, should be equals to 4 (3+1)
int result = future.get();
std::cout << "Last operation result is equals to " << result << std::endl; I'll add this example to the readme whenever I have some time. Thanks for pointing that out. PS: If you dont like std::bind you can also use lambdas. Hope this helps mariano. |
Hi, I was using your thread pool implementation. And I implemented a method to address this in a different way. I post here if it helps:
By the way, thank you for your library, you really did a good work! |
Hi,
I assume the answer is "no" of course, but, before I make that conclusion, I would prefer asking in here :). Can I somehow have a member-method (non-static) be my executed function when submitting?
Thanks!
The text was updated successfully, but these errors were encountered: