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!