c++ - Why is this pointer needed when calling std::call_once()? -
"C ++ concurrency in action" in book "§3.3.1, when starting a thread-safe lazy launch of a class member From , the third parameter is the parameter passing through the function PS: Removing UPDATED: The problem is more explicitly in the book "C + + Concurrency "" When to start the same work, then If the first argument ( Why is this indicator necessary when calling STD: call_once ()? Because This could have been applied with a different example, although in this case it would not be understandable: std :: call_once () , it gives the following example:
#include
X :: open_connection () .
is given to
X :: open_connection ()
this Need Pointer?
std :: call_once (connection_init_flag, and x :: :: open_connection, this);
indicator will cause C 2064 error:
Error C2064: term Do not evaluate 0 logic in action
std :: async :
std :: call_once ) Is an indicator for a member function, the second argument (
std :: call_once to be third) provides the object on which the member functions (either directly or, an indicator, or
std :: ref ) is wrapped, and the remaining argument is used for member functions . Otherwise, the second (
Std :: call_once ) and subsequent logic functions or callable object specification are passed as arguments Are the first arguments as AD.
open_connection is a non-static data member, it has to be called on some, and such a similar example is,
this (Technically, the first parameter for
this in the non-static member functions is an inherent first parameter). )
xx; Std :: call_once (connection_init_flag, & x :: open_connection, & amp; x);
Comments
Post a Comment