Home > Back-end >  STD: : thread parameter hermit type conversion problem
STD: : thread parameter hermit type conversion problem

Time:04-23

Code is as follows, there is a int hermit type conversion to the Test, I said look at some places, the hermit type conversion may appear problem, but my analysis is tested, hermit type conversion occurs in the child thread, just make sure the incoming int value is effective, there is no problem, but is int value transfer copy to the thread in space, must be effective, and hermit type conversion is also in the space of the child thread, for the problems such as Pointers to STD: : string hermit type conversion, because in this case, the end of the main thread, pointer will fail, but for such as general type, there is no this kind of question,
 
The class Test
{
Public:
The Test (int)
{
STD: : cout & lt; <"The Test:" & lt; }
};

Void print (const Test & amp; T)
{
STD: : cout & lt; <"Print:" & lt; }

Int main (int arg c, char * argv [])
{
STD: : thread t (print, 1);
T.d etach ();
return 0;
}

CodePudding user response:

Const T& Life cycle will be automatically extended temporary variables,

CodePudding user response:

I think zha implicit conversion is in the main thread,
It doesn't matter, as pointer itself pointer itself is by value, related to pointer pointing to the life cycle of the object,
  • Related