-
Notifications
You must be signed in to change notification settings - Fork 127
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
Why does the function with arguments have errors? #26
Comments
What's the right thing to do? |
Use a lambda to decide how your function is going to be invoked. E.g. pool.post([]{ t(5); }); |
Just test pool.post([]{ t(5); }); code and there's an error occurred. Error C3493: "t" cannot be caught implicitly because the default capture mode has not been specified #include "thread_pool.hpp" int f(int j) int main(int argc, char **argv) |
You doing it wrong. Use something like that:
PS. It tell you directly - ""t" cannot be caught implicitly because the default capture mode has not been specified". Specify capture mode in lambda. |
Thank you so much for your reply !but, there are still some errors. Error C2664 "STD: : function < _Ret (void) > : : function (STD: : function < _Ret (void) > &&)" :1 cannot be parameters from the "main: : < lambda_52a96aedc09236acf9c18022602966b7 >" into "STD: : nullptr_t ConsoleApplication4" c: \ program files \ Microsoft visual studio (x86) vc 14.0 \ \ include \ the future 582 #include "thread_pool.hpp" class cc{ int main(int argc, char **argv) |
What would you like to achieve on so complex manner? To post subroutine call to pool just enough to wrap it in lambda directly:
No future, no bind requires. Also keep in mind: using future here lead to serialization and makes pool useless. |
so, there are still some errors.please use the vs2015 run this code to see your result. **
please, |
Ah, vs2015. AFAIK this version does not fully C++11 compliant. Try to use more fresh compiler. Unfortunately, I cant verify due to does not using Windows. |
Thank you so much for your reply !but, there are still some errors. Error C2664 "STD: : function < _Ret (void) > : : function (STD: : function < _Ret (void) > &&)" :1 cannot be parameters from the "main: : < lambda_52a96aedc09236acf9c18022602966b7 >" into "STD: : nullptr_t ConsoleApplication4" c: \ program files \ Microsoft visual studio (x86) vc 14.0 \ \ include \ the future 582 #include "thread_pool.hpp" class cc{ int main(int argc, char **argv) |
Your code produces syntax error: test12.cc: In function 'int main(int, char**)': To make it work it is enough to write: #include "thread_pool.hpp" class cc{ int main(int argc, char **argv) pool.post([&] { obj.f(5); } ); getchar(); |
Thank you so much for your reply !but, there are still some errors. #include "thread_pool.hpp" struct A { int main()
} |
Thank you so much for your reply !but, big brother... I want use std::future method to get thead result value. struct A { int main()
|
Using future is bad idea here, due to thread pool serialization. With this you pool will execute one task a time. |
thanks for the warning, But I still want to use std::future method... How should I pass parameters? |
If you're insist....On your responsibility:
This works. Don't understand, why thread pool here... It will not work as pool. Just enough to use std::async. But I'm not C/C++ programmer. |
Thank you, you are a kind one.
|
error C2660 “std::packaged_task<int (int)>::operator ()”: The function does not take zero arguments
The text was updated successfully, but these errors were encountered: