I am reading a book, and there is below code :
mActionBinding[Fire].action = derivedAction<Aircraft>(
std::bind(&Aircraft::fire, _1));
the argument that is sent to derived action, will be sent two arguemnts later.
template<typename GameObject, typename Function>derived action function
std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
{
return [=](SceneNode& node, sf::Time dt) expression
{
assert(dynamic_cast<GameObject *>(&node) != nullptr);
fn(static_cast<GameObject &>(node), dt);
};
}
the declaration of fire is this which is in Aircraft class:
class Aircraft:public SceneNode
{
public:
void fire()
};
I have read some articles about std::bind, but honestly I haven't seen anything like this.this is much more complex.
let me sort my questions:
1-based on my reading, this std::bind has three arguments! the member function, implicit class name and _1. is it true? does this mean, when we invoke it in derivedAction,instead of static_cast<gameObject &>(node)
, "this" will be sent to it?
2-fire has no argument at all!(except for implicit this), so why _1 give us no error? and how "dt" will be sent to it?
I am a little confused, references gives examples of simple uses, any other information about std::bind
, will be appreciated.