The function pointer of c++11 tips __jquery

Source: Internet
Author: User

C++11 has a one-time function lambda, so giving a lambda directly to the callback function can reduce the complexity of the overall class design.

But if the callback interface is a C language, then only one lambda can be used as a callback, or a lambda without a capture.

As follows:

void Maincb (void (*) (int)) {};

{
    main ([] (int) {}) ();
}
If you take any captures, the compiler does type derivation with a "lambda" label, indicating that this is a lambda function, resulting in a different type of deduction and a callback type.

Without capture, the compiler simply deduces the lambda expression as a normal function, so it can be used directly as a function pointer.

But if the lambda expression is passed into the Std::function object, then whether or not the capture is returned by the function->target is null, as the underlying code can see, The typeid of the template parameter that is passed in by target differs from the typeid of the function pointers stored within the functions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.