When STD: ref encounters a pre-declaration

Source: Internet
Author: User

When STD: ref encounters a pre-declaration

The reason is:

There is a pre-declared type

Then another callback function uses a reference of session_t (note that the following code can be compiled)

Here, Handler _ (Session ,...) It can be seen as an STD: function object, and the prototype of handler is

[] (Network: session_t &,...) {}; Here handler _ only needs to forward the session in reference mode, but fails to mutate after STD: ref is added to the session, for example, Handler _ (STD: ref (Session ),...); The compiler complained,

This session_t is not a complete type. Yes, session_t is a pre-declaration. It is unnecessary because it does not use members of this type. However, it can be compiled by copying values.

Let's take a look at the implementation of STD: ref:

According to the error message, STD: is_abstract considers session_t as not a complete type.

My question is, why can I copy data by value? But will not result in the copy effect? I am confused!

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: info-contact@alibabacloud.com 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.