boost mutex strange error with private member

后端 未结 2 5055
青春惊慌失措
青春惊慌失措 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.

提交回复
热议问题