Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use the bind function in C++

Shulou Source: shulou.com Published: 2022-06-02 06:49:56 10月03日 Update

How to use the bind function in C++? for this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

The bind function is in the header file functional

The general form of calling bind:

Auto newCallable = bind (callable, arg_list)

NewCallable is a new callable object, and callable is the original callable object. When newCallable is called, callable is called and the arg_list parameter is passed.

Arg_list parameter

The parameter list contains _ n placeholders and other parameters, _ n is the parameter of the new callable object, and the other is the parameter of the original calling object, and the placeholder is defined in the std::placeholders namespace.

Auto g = bind (f _ a _ r _ b _ c _ r _ 1); / / g is a callable object with two parameters.

G (_ 1 recording 2); / / pass two parameters of g to f call execution

Suppose you call g (x ~ ~ y), then f (a ~ b ~ ~ y ~ c ~ x) will be called.

Bind reference parameter

Using ref or cref to bind, cref creates a const reference.

So much for the answers to the questions on how to use the bind function in C++. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Tags: Parameters objects tunable functions questions two more help solutions easy easy creative content guys partners forms files methods knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Microsoft vpn Apple Xiaomi