I have been trying to construct a thread using class members. I am unable to determine why the compiler (VS2015) keeps complaining.
I have a class with two member functions. Load(...) takes in arguments by reference and is public. While ProcessQ(...) is private ,takes arguments by reference. ProcessQ is passed onto the thread. But I keep getting the error
"unknown-type std::invoke(_Callable &&,_Types &&...)" at the constructor
thread(&FileProcessor::ProcessQ, ref(fileQ), ref(fpQ), folder);
Seems that I have missed out constructor syntax of thread?
typedef vector<string> FPTemplate;
class FileProcessor
{
public:
void Load(string folder, concurrent_queue<string>& fileQ, concurrent_queue<FPTemplate>& fpQ);
private:
void ProcessQ(concurrent_queue<string> &fileQ, concurrent_queue<FPTemplate> &fpQ, string folder);
};
And here is my Load(...) function
void FileProcessor::Load(string folder,concurrent_queue<string>& fileQ, concurrent_queue<FPTemplate>& fpQ)
{
// Create threads and exectue
const short nThreads = 8;
thread fileProcessorThreads[nThreads];
for (short i = 0; i < nThreads; i++)
{
fileProcessorThreads[i] = thread(&FileProcessor::ProcessQ, ref(fileQ), ref(fpQ), folder);
}
for (auto& th : fileProcessorThreads)
{
th.join();
}
}