views:

60

answers:

3

I have a class declaration in Utils.h:

    class Utils {
 private:
     static boost::mutex outputMutex;
    };

In the cpp file:

boost::mutex Utils::outputMutex = boost::mutex();

I get:

Error 1 error C2248: 'boost::mutex::mutex' : cannot access private member declared in class 'boost::mutex'

If we look inside boost/thread/win32/mutex.hpp we see:

namespace boost
{   
    class mutex:
        public ::boost::detail::underlying_mutex
    {

    // ...       

    public:
        mutex()
        {
            initialize();
        }

Does anyone know what I'm missing here? It used to compile OK on a different machine with VS2008.

Thank you.

A: 

It looks like you're declaring Utils::outputMutex twice, once in the class declaration and then again in the .cpp. Also, the second declaration is being assigned the "return value" of the constructor, which isn't possible. What happens if you remove the second declaration?

chrisaycock
its static initialization/definition
aaa
@aaa: Your answer is right, you should undelete it.
GMan
There needs to be a "vote to undelete".
dreamlax
+2  A: 

The .cpp file should be:

boost::mutex Utils::outputMutex;

There's no need for an assignment. It will be constructed appropriately.

Ferruccio
It isn't assignment, it's copy initialization.
GMan
This works. If I remember right (not sure) it needed the assignment in VS2008. Cheers :)
Mau
+3  A: 

What you have is copy-initialization, and is equivalent to:

boost::mutex Utils::outputMutex(boost::mutex());

Which calls the copy-constructor. However, mutex is noncopyable. Just let it default construct:

boost::mutex Utils::outputMutex;
GMan
to be honest, I was not quite sure since it was mentioned it worked before.
aaa