#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 );
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^