I am trying to call some of my member functions using threads. Suppose I have this
class myclass
{
public:
myclass();
double function1();
void function2();
};
myclass::myclass()
{}
double myclass::function1()
{
...
return a double;
}
void myclass::function2()
{
//use a thread to call function 1
std::thread t(function1);//doesnt work!-wont compile
std::thread t2(myclass::function1);//doesnt work either -wont compile
std::thread t3(&myclass::function1);//doesnt work here either - wont compile
}
How can I call a member function by a thread inside another member function in C++? I am using Visual Studio 2013 Preview by the way.
UPDATE 2:
I did as i was told , some sections of code now compiles just fine and some others just don't!
this is the new sample code which generates the error :
class xGramManipulator
{
public:
xGramManipulator();
void ReadMonoGram();
void ReadBiGram();
void ReadMonoGram(double &);
void ReadBiGram(double &);
void CreateMonoGramAsync();
void CreateBiGramAsync();
};
xGramManipulator::xGramManipulator()
{
}
void xGramManipulator::CreateMonoGramAsync()
{
thread t(&xGramManipulator::ReadMonoGram, this);
}
void xGramManipulator::CreateBiGramAsync()
{
thread t = thread(&xGramManipulator::ReadBiGram, this);
}
The above code(those two Async member functions) generates the following errors :
Error Message:
error C2661: 'std::thread::thread' : no overloaded function takes 2 arguments