I have a strange error.
class INST
{
public:
boost::mutex m_mutex;
};
std::vector<INST> m_inst;
error C2248: 'boost::mutex::mutex' : cannot access private member declared in class 'boost::mutex' see declaration of 'boost::mutex::mutex'
However, my other class is fine,
class VIEW
{
public:
boost::mutex m_mutex;
};
VIEW m_view;
Am I missing something here? I have tried to declare m_mutex to private, but still have the same problem.
Thanks.
mutexes can't be copied, so you can't place them in a container which would copy the mutex. The error is likely referring to the private copy constructor of the mutex.
I realize that this question is really old, but I stumbled upon the same problem earlier today and Google lead me here. However, the proposed solution did not suit me so I wanted to describe how I solved it in my own project.
I have a vector of classes just like you, and I manage these in such a way so that once access to the members of the vector begins, the vector will never be resized again. I do want the ability to resize the vector a few times at the start, though, before processing begins. I also wanted to allow the threads to operate on any of the items in the vector in a random access fashion.
I solved the problem with the mutex by allocating it dynamically in the constructor of the class, and destroying it in the destructor. Naturally, if you do this you must guarantee that nobody is waiting on the mutex when you delete it. This solution works for me because I never copy objects out of the vector, I only access them inside of the container.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With