querti
querti

Reputation: 77

C++ threading - no matching function for call to

This is my first time using threads in c++ and I have some issues with it. I am getting error

error: no matching function for call to ‘std::thread::thread(<unresolved overloaded function type>, __gnu_cxx::__alloc_traits<std::allocator<packetInfo> >::value_type*)’

This is my code excerpt:

std::vector<packetInfo> sentPackets; // global var

void renewIP(struct packetInfo *currentPacket) {
...//code
}

void anotherFuntion() {

    ...
    std::thread renewTimer(renewIP, &(sentPackets[i]));
    renewTimer.detach();
    ...
}

I have absolutely no idea what am I doing wrong or why am I getting the error.

Thanks.

Upvotes: 1

Views: 323

Answers (1)

John Zwinck
John Zwinck

Reputation: 249153

The error tells you directly:

<unresolved overloaded function type>

You must have multiple overloads of renewIP, and the compiler doesn't know which one you want. You can either rename them to make them not ambiguous, or make it explicit via a cast:

std::thread renewTimer((void(*)(struct packetInfo*))renewIP, &(sentPackets[i]));

Upvotes: 5

Related Questions