I'm curious to what I'm doing wrong here. I have the following function:
indexer.h:
class DtIndexer {
public:
static void ThreadedIndex(string folderPath);
indexer.cpp
void DtIndexer::ThreadedIndex(string folderPath) {
cout << "\t-> Indexing Folder: " << folderPath << endl;
cout << "\t->> Done..." << endl;
}
and my call to create the threads:
void DtIndexer::UpdateIndex(DatabaseData &data, bool isCreate) {
vector<thread> threadList;
for (string &s: data.FilePaths) {
const char *folder = GetFolderPath(s, data.IncludeSubFolders);
cout << "\t-> Adding Folder to Thread: " << folder << endl;
threadList.emplace_back(thread(ThreadedIndex, folder));
}
for_each(threadList.begin(), threadList.end(), mem_fn(&thread::join));
}
My output is this:
-> Adding Folder to Thread: /index_2185<+>
-> Adding Folder to Thread: /index_1065<+>
-> Indexing Folder: /index_1065<+>
->> Done...
-> Indexing Folder: /index_1065<+>
->> Done...
Now, I'm pretty sure it has to deal with the static for the method, but if I remove static I get this:
error: invalid use of non-static member function ‘void DtIndexer::ThreadedIndex(std::__cxx11::string)’ threadList.emplace_back(thread(ThreadedIndex, folder));
Also, If I remove static
and add the function to the thread like this:
threadList.emplace_back(thread(&DtIndexer::ThreadedIndex, folder));
I get:
required from here /usr/include/c++/6/functional:1286:7: error: static assertion failed: Wrong number of arguments for pointer-to-member static_assert(_Varargs::value
I'm still fairly new to C++, so, any advice will be appreciated.