mardi 29 mars 2016

"Failed to specialize function template" when trying to pass member function of another class

I have been trying to assign class's member function to a std::function but it throws compile time error Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)

Below is the header file of that class :

class TypeAnalysis {
public: 
    bool AnalysisHelper(std::string filePath);
    void createTypeTable(std::string dir, std::string pattern, size_t nThread = 3);
    std::vector<std::string> getFiles(std::string dir, std::vector<std::string> patterns);
private:

};

And below is createtypeTable function where I am assigning AnalysisHelper method to std::fnuction object.

void TypeAnalysis::createTypeTable(std::string dir, std::string pattern, size_t nThread)
{
    Threadpool<bool, std::string> tp(10);
    DataContext dc;
    tp.start();
    std::vector<std::string> patterns = SH::split(pattern);
    std::vector<std::string> files = getFiles(dir, patterns);
    std::function<bool(std::string)> w = &TypeAnalysis::AnalysisHelper; //I think issue is here
    try {
        if (files.size() > 0) {
            for (size_t i = 0; i < files.size(); i++) {
                WorkItem<bool, std::string> *wi1 = new WorkItem<bool, std::string>(&w, &files[i]);
                tp.doWork(wi1);
            }
        }
    }
    catch (std::exception ex) {
        std::cout << ex.what();
        return;
    }
    tp.doWork(nullptr);
    tp.wait();
    DataContext::getContextThreadPool().doWork(nullptr);
}

When I tried to do the same without any class definition (AnalysisHelper was Glabal function and main had same body as createTypeTable), it worked fine.

Any idea whats wrong?

Aucun commentaire:

Enregistrer un commentaire