Thursday 15 March 2012

c++ - Boost threads - passing parameters by reference -


In my application there is a code that is similar to the following code

  zero some class :: Other method (Std :: vector & lt; std: string & gt; & amp; g) {g.pushback ("something"); } Zero SomeClass :: SomeMethod () {std :: vector & lt; Std :: string & gt; V; Promotion: Thread T (Promotion :: Tie (and some class :: Other method, This, V) T. Joint (); std :: cout & lt; v [0]; // Why is it empty When created on vector stack} I wanted to know that vector v is empty when the vector is made on a heap and when it is made on a heap, it works. The code above was hoping for the vector to remain in the field, even if it was made on the stack.   

Bind copies its parameters. Use the Promotion :: Reference :

  boost :: thread T (boost :: bind (& SomeClass :: OtherMethod, Promotion: Ref (V))    

No comments:

Post a Comment