Boost logo

Boost Users :

From: Nat Goodspeed (nat_at_[hidden])
Date: 2008-05-08 09:44:23


Kevin Martin wrote:
> On 8 May 2008, at 04:09, Peisheng Wang wrote:
>
> You are importing the namespace boost, so mutex is both a variable
> name and a type name, the compiler gets confused.

...
> boost::mutex mutex;
>
> void increment_count()
> {
> boost::mutex::scoped_lock lock(mutex);

Yes. Specifically, the line above could be interpreted as the
declaration of a function lock() accepting an unnamed mutex by value and
returning a boost::mutex::scoped_lock (the "most vexing parse").

Kevin's suggestion is probably best to keep things straight for the
reader as well as for the compiler. It might also work to use
assignment-style initialization? I haven't tried it for this case.

     boost::mutex::scoped_lock lock = mutex;

I mention that more as a tactic for future function-vs.-object
declaration ambiguities than for this particular one.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net