std::thread pass by reference calls copy constructor

std::thread takes its arguments by value. You can get reference semantics back by using std::reference_wrapper:

std::thread newThread(session, &sock, std::ref(logger));

Obviously you must make sure that logger outlives the thread.

Leave a Comment