boost mutex strange error with private member

后端 未结 2 3674
青春惊慌失措
青春惊慌失措 2021-02-20 19:18

I have a strange error.

class INST
{
public:
boost::mutex m_mutex;
};

std::vector m_inst;

error C2248: \'boost::mutex::mutex\' :

相关标签:
2条回答
  • 2021-02-20 19:27

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题