I have started trying to learn std::function after reading Scott Meyers Effective C++. I made the following sample program to give a std::function object to a class
#include <iostream>
#include <string>
#include <functional>
class FlyBehaviour
{
public :
void fly()
{
std::cout<<"Flying";
/* Work Here */
}
};
typedef std::function<void(const FlyBehaviour&)> FlyFunc;
class Duck
{
public :
Duck(FlyFunc flyFunc) : _flyFunc(flyFunc){}
private :
FlyFunc _flyFunc;
};
int main()
{
Duck(&FlyBehaviour::fly);
}
Compiling the above code gives me the following error
error: invalid use of qualified-name 'FlyBehaviour::fly'
On research, most of the internet points to using std::bind/boost::bind as a solution. Can someone please tell me how to apply it, especially where do I need to declare the object to which function is binded?