Here is the code. It does not compile in vs2013, but does compile in gcc4.8
error C2665: 'std::thread::thread' : none of the 4 overloads could convert all the argument types
Since I am using vs2013, can anyone provide workaround?
#include <iostream>
#include <thread>
template<typename T>
class TestClass
{
public:
TestClass(){};
~TestClass(){};
T t;
template<typename U>
void fun(U u)
{
std::cout << "fun: " << u << '\n';
}
};
int main()
{
TestClass<double> A;
auto aaa = std::thread(&TestClass<double>::fun<int>, &A, 1);
}
There is another way you can achieve above problem,If you would mind ! First just look explicit constructor of thread object:
f - Universal reference for function object.
args - variadic arguments for function(functor) f.
(I am not going to explain deeper and deeper about variadic calling used here). So now we know we can deal with functors therefore, Define a functor(function object) like below :
//Please notice here I've not used any locker guard system. If you use static function you don't have to bind respective instance each time this may change your expected run-time behavior therefore you have to managed,
You could simply use a lambda rather than monkeying with member function pointers: