我在MessageQueue类中使用boost mutex作为以下方法中的私有成员
void MessageQueue::Dequeuee()
{
Request rq(messageWareHouse.front().reqID,messageWareHouse.front().seq,
messageWareHouse.front().sMessage);
while(true)
{
boost::unique_lock<:mutex> lock(qMutex);
qCond.wait(lock);
**reqCollection**.find(messageWareHouse.front().reqID)->second.addSegments(messageWareHouse.front().seq,
messageWareHouse.front().sMessage );
}
....reqCollection是一张地图
map reqCollection;内部请求时,我尝试初始化互斥我得到下面的错误
class Request
{
private:
size_t RequestID;
public:
boost::mutex qMutex;
Request(size_t requestID,size_t seq, std::string sMessage);
void addSegments(size_t seq, std::string sMessage);
};据我搜索谷歌here这个错误,该问题的解决方案是
Place (smart) pointers for the mutex or the class containing the mutex
但这是否意味着我只能通过传递指针在整个项目中使用一个互斥变量?为什么提高是保护互斥体
错误是
Error 7 error C2248: 'boost::mutex::mutex' : cannot access private member declared in class 'boost::mutex'