jeudi 28 mai 2015

std::function to a const member

I have a member function which is const. I want to create callbacks to that function. I usually define them as:

typedef std::function<double(std::string)> callback;

But when I bind it like (from within another const function):

std::bind(&MyClass::myconstFunct,
            this, std::placeholders::_1)

It complains that I cannot use "this" since I'm in a const function and std::bind takes a non-const reference to this. I tried to use const_cast on this but no luck.

Any idea on how to tell bind that the function is const and therefore "this" is a const reference too? Is there a std::const_bind?

Thanks!

Aucun commentaire:

Enregistrer un commentaire