Search code examples
c++mingw32

std::tr1::bind() several compilation error


i try to use bound function but my code can't be compiled. I use Qt5.3.1 with MinGW 4.8.

my class :

class ProcessSearch : public QObject
{
    Q_OBJECT
public:
    explicit ProcessSearch(QObject *parent = 0);
    void Search(const QString startDir, const QString destDir, QList<QString> wavList);

signals:
    void status(int);
    void statuslog(QString);

private:
    QString startDir, destDir;
    QList<QString> wavList;

};

i try to bind the Search method like this :

auto f = std::tr1::bind(&ProcessSearch::Search, std::tr1::placeholders::_1, pathDest, wavList);  
f(wavpathList.at(0)); 

But i have several errors when i try to built it .... The first error :

no match for call to '(std::tr1::_Mem_fn<void (ProcessSearch::*)(QString, QString, QList<QString>)>) (const QString&, QString&, QList<QString>&)'  

where is my mistake ? thx


Solution

  • You probably need the instance of ProcessSearch during the bind.

    std::tr1::bind(&ProcessSearch::Search, this, ... )
    

    Note, think about using C++11 and you can easily express those connections with lambdas. Or at least consider std::bind (e.g., [CppReference] http://de.cppreference.com/w/cpp/utility/functional/bind).