How std::bind increases number of arguments passed to a function?

shayan

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.

Oktalist
std::bind(&Aircraft::fire, _1)

1) There are two arguments passed to std::bind. The first argument is &Aircraft::fire, a pointer to the member function Aircraft::fire. The second argument is std::placeholders::_1, found by unqualified lookup due to the presence of a using namespace std::placeholders somewhere.

fn(static_cast<GameObject &>(node), dt)

2) The argument static_cast<GameObject &>(node) replaces the _1 placeholder. Aircraft::fire has one parameter, the implicit this, so static_cast<GameObject &>(node) is supplied as the implicit this argument to Aircraft::fire. The argument dt would replace the _2 placeholder, but since there is no _2, it is ignored.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Is there a limit to the number of arguments passed to a fortran function?

From Dev

validate the number of arguments passed to method/function

From Dev

Bind to function with an unknown number of arguments in C++

From Dev

How can I find out the number of arguments that are actually passed to a bash function?

From Dev

std::function to variadic member function and then bind variadic template arguments

From Dev

Decorators: how arguments are passed to wrapped function?

From Dev

How to check the type of passed arguments to variadic function

From Dev

How are arguments passed to function pointers in C?

From Dev

How to check the type of passed arguments to variadic function

From Dev

How many arguments are passed in a function call?

From Dev

Why std::bind cannot resolve function overloads with multiple arguments?

From Dev

How to bind an arguments object to a function in JavaScript?

From Dev

How to bind arguments to child function in Vue

From Dev

The arguments are not passed into the function correctly

From Dev

How to check for wrong number of parameters passed to a function

From Dev

How to use std::bind with std::function and std::map

From Dev

How do I count the number of macro arguments passed to a variadic macro?

From Dev

How do I validate the total number of passed arguments?

From Dev

How do I validate the total number of passed arguments?

From Dev

How to use template function parameter in std::bind?

From Dev

how to pass a std::bind object to a function

From Dev

How to bind, store and execute a std::function object?

From Dev

How to use template function parameter in std::bind?

From Java

How to pass all arguments passed to my bash script to a function of mine?

From Dev

How does one ignore unexpected keyword arguments passed to a function?

From Dev

modern javascript rest function giving n number of outputs for n number of arguments passed

From Dev

How to get passed arguments?

From Dev

How to convert std::bind (or lambda) to std::function in deduced context?

From Dev

How to define a function with a variable number of arguments?

Related Related

  1. 1

    Is there a limit to the number of arguments passed to a fortran function?

  2. 2

    validate the number of arguments passed to method/function

  3. 3

    Bind to function with an unknown number of arguments in C++

  4. 4

    How can I find out the number of arguments that are actually passed to a bash function?

  5. 5

    std::function to variadic member function and then bind variadic template arguments

  6. 6

    Decorators: how arguments are passed to wrapped function?

  7. 7

    How to check the type of passed arguments to variadic function

  8. 8

    How are arguments passed to function pointers in C?

  9. 9

    How to check the type of passed arguments to variadic function

  10. 10

    How many arguments are passed in a function call?

  11. 11

    Why std::bind cannot resolve function overloads with multiple arguments?

  12. 12

    How to bind an arguments object to a function in JavaScript?

  13. 13

    How to bind arguments to child function in Vue

  14. 14

    The arguments are not passed into the function correctly

  15. 15

    How to check for wrong number of parameters passed to a function

  16. 16

    How to use std::bind with std::function and std::map

  17. 17

    How do I count the number of macro arguments passed to a variadic macro?

  18. 18

    How do I validate the total number of passed arguments?

  19. 19

    How do I validate the total number of passed arguments?

  20. 20

    How to use template function parameter in std::bind?

  21. 21

    how to pass a std::bind object to a function

  22. 22

    How to bind, store and execute a std::function object?

  23. 23

    How to use template function parameter in std::bind?

  24. 24

    How to pass all arguments passed to my bash script to a function of mine?

  25. 25

    How does one ignore unexpected keyword arguments passed to a function?

  26. 26

    modern javascript rest function giving n number of outputs for n number of arguments passed

  27. 27

    How to get passed arguments?

  28. 28

    How to convert std::bind (or lambda) to std::function in deduced context?

  29. 29

    How to define a function with a variable number of arguments?

HotTag

Archive