#include <thread>
struct Callable
{
void start() {};
void start(unsigned) {};
};
int main()
{
Callable some_object;
std::thread some_thread( &Callable::start, &some_object );
some_thread.join();
}
This code does not compile because &Callable::start is ambiguous. Is there a way to specify which overload should be used in std::thread constructor?
You can cast:
using callback_type = void (Callable::*)();
std::thread some_thread(
static_cast<callback_type>(&Callable::start), &some_object );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With