I am fimilar with std::function , but i am reading a book that there is a code like this :
template<typename GameObject, typename Function>
std::function<void(SceneNode&, sf::Time)> derivedAction(Function fn)
{
return [=](SceneNode& node, sf::Time dt)
{
assert(dynamic_cast<GameObject *>(&node) != nullptr);
fn(static_cast<GameObject *>(&node), dt)
}
}
then the book use template like this :
Command moveLeft;//command is a structure
moveLeft.action//action is a std::function object
= derivedAction<Aircraft>(AircraftMover(-playerSpeed, 0));
//derivedAction specify<Aircraft> ???
my questions are : 1-derivedAction must be an object of std::function , i have checked references but i haven't found this kind of initialazation with {} , how this works ? 2-it is complicated to me , to understand the lambda expression , and why there is a return for it ? i am pretty confused about this peice of code , any explination would be appreciated
Aucun commentaire:
Enregistrer un commentaire