This is a classic C ++ trap. thr1 is not what you think (stream object). This is a declaration of a function that takes an instance of A as a parameter. Wrap it in parentheses to force the intended interpretation:
boost::thread thr1((A())); boost::thread thr2((A()));
Detailed explanation
The syntax of the original syntax is equivalent to:
boost::thread thr1(A);
Why does the compiler allow ignoring empty parentheses? Honestly, I'm not sure. I am not an expert in C ++ and - but I think this is due to the following thought: A *a = A (*a) , therefore A * = A (*) ; similarly, A a = A (a) , therefore A = A () .
Look to the future!
The upcoming C ++ standard will fix this as a byproduct of its new initialization syntax:
boost::thread thr1{A()}; boost::thread thr2{A()};
source share