这是我第一次在c ++中使用线程,但我遇到了一些问题。我遇到错误
error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, __gnu_cxx::__alloc_traits<std::allocator<packetInfo> >::value_type*)’
这是我的代码摘录:
std::vector<packetInfo> sentPackets; // global var
void renewIP(struct packetInfo *currentPacket) {
...//code
}
void anotherFuntion() {
...
std::thread renewTimer(renewIP, &(sentPackets[i]));
renewTimer.detach();
...
}
我完全不知道我在做什么错或为什么我得到了错误。
谢谢。
该错误直接告诉您:
<unresolved overloaded function type>
您必须具有的多个重载renewIP
,并且编译器不知道您要重载哪个。您可以重命名它们以使其不模糊,也可以通过强制转换将其显式显示:
std::thread renewTimer((void(*)(struct packetInfo*))renewIP, &(sentPackets[i]));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句