Can any body help me figure it out? Thanks.

g++ boo_t.cpp
-L../resource/boost_1_35_0/bin.v2/libs/thread/build/gcc-4.1.2/release/threading-multi/libboost_thread-gcc41-mt-1_35.so.1.35.0
-Lpthread
boo_t.cpp: In function ‘void increment_count()’:
boo_t.cpp:14: error: reference to ‘mutex’ is ambiguous
boo_t.cpp:10: error: candidates are: boost::mutex mutex
/usr/include/boost/thread/mutex.hpp:35:
error: class boost::mutex
code:
#include

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. You have a similar
problem with std::count. Changing the variable names to amutex and
acount fixes the problem. The below code compiles and runs for me.
#include

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.
participants (3)
-
Kevin Martin
-
Nat Goodspeed
-
Peisheng Wang