mercredi 8 mars 2017

false-positive error using std::functional in vs2015

I have implemented some test functionals yesterday and everything compiled and worked fine without errors. Today i came back to my PC and my std::bind's are underlined red but compile without error. Seems like Intellisense and the compiler do not agree on the std::bind type. How can I fix this?

#include <functional>

class MyClass {
public:
    int doE() {
        return 0;
    }

    int doF() {
        return 1;
    }
};


void main()
{
    MyClass obj;
    std::function<int()> f = std::bind(&MyClass::doE, obj); // underlined red
    std::cout << f();
}

The error message is as follows:

Error (active) no suitable user-defined conversion from "std::_Binder<std::_Unforced, int (MyClass::*)(), MyClass &>" to "std::function<int ()>" exists functionals c:\functionals\functionals\thirdFunctionOnObject.h

I do have the same error type (Intellisense saying there is an error, but it compiles just fine) in more sophisticated code, where I used std::mem_fn().

Aucun commentaire:

Enregistrer un commentaire