c++ - 线程 - 没有要调用的匹配函数

标签 c++ multithreading c++11

我有一个叫做发送的函数

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/

相关文章:

c++ - vector 调整大小奇怪的行为

multithreading - 何时在 asio 中使用异步操作

c++ - 我的 vector 相交函数有什么问题?

c++ - 是否存在类声明虚方法而编译器不需要使用 vptr 的情况?

c++ - 并发队列内存消耗爆炸,然后程序崩溃

c++11 - make_unique 的异常感知 malloc 版本

c++ - 为什么不能从 C++11 中的非限定成员函数名中获取指向成员的指针?

c++ - 是否可以在运行时切换到不同的基类构造函数?

c++ - sigc::mem_fun中的C++ “no match for call”错误

c# - 不可重入 C# 定时器