我有一个叫做发送的函数
void send ( mutex *m,
socklen_t addr_size,
sockaddr_storage serverStorage,
double PLP ,
int size_of_file ,
char ** char_file ,
int *total ,
int *next_seq_to_send ,
int *base_seq ,
int client_socket ,
int *window_size ,
vector <packet> *window_buffer ,
vector <bool> *wind_slots )
我想用这个函数来创建这样一个线程
std::thread send_thread (send, &m ,addr_size,
serverStorage, PLP , size_of_file,
char_file , &total,
&next_seq_to_send,
&base_seq, client_socket,
&window_size,&window_buffer,
&wind_slots );
但是我得到了一个错误
no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, std::mutex*, socklen_t&, sockaddr_storage&, double&, int&, char*&, int*, int*, int*, int&, int*, std::vector<packet>*, std::vector<bool>*)’
rage, PLP , size_of_file , char_file , &total , &next_seq_to_send , &base_seq , client_socket , &window_size , &window_buffer , &wind_slots );
^
有什么帮助吗?
最佳答案
std::ref
在您需要通过引用将对象传递到线程函数(或在类似情况下)时使用。 不过,这不是您的情况;该函数不接受引用,它接受指针(并按值获取它们)。只需将您对 std::ref(x)
的所有使用更改为 &x
以获取参数的地址,就可以了。
关于c++ - 线程 - 没有要调用的匹配函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41090171/