gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 01:05:10 25 4
gpt4 key购买 nike

这是我第一次在 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]));

关于C++ 线程 - 没有匹配的调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48989917/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com