问题
Okay I am trying to make a thread in c++ that runs the function storePose();
that function takes nine parameters as doubles. Every time I try to create the thread it complains about the parameters. I will post my code below. I have not a clue why this wont work. Thanks in advanced
CODE:
std::thread t(storePose,x_position, y_position, z_position, azimuth, att_pitch, att_roll, yaw, cam_pitch, cam_roll);
t.detach();
ERROR GIVEN:
12 IntelliSense: no instance of constructor "std::thread::thread" matches the argument list
argument types are: (<unknown-type>, double, double, double, double, double, double, double, double, double)
EDIT: Sorry I forgot to mention that I am using Visual Studio 2012
回答1:
Microsoft Visual C++ (2012) doesn't have support for variadic templates. They have something called faux variadics that stamp out overloads via macros. The problem is that there is a limit to the number of arguments you can pass to a variadic template and by default that limit is 5. You can adjust the limit by defining _VARIADIC_MAX
to be a larger number (e.g. for a limit of 10 set /D_VARIADIC_MAX=10
)
See this and this.
回答2:
Too many arguments, put them in a struct and give the struct to the thread function and deal with the args in the struct.
来源:https://stackoverflow.com/questions/26919664/cant-pass-arguments-to-thread-function