0

I am new to both concepts shared_ptr and mutex (boost or not boost). I am trying to use it in my classes :

typedef boost::shared_mutex Lock;
typedef boost::unique_lock< Lock > WriteLock;
typedef boost::shared_lock< Lock > ReadLock;

class subscriptionInfo 
{
public:
//this is not a copy constructible class. so I have to use shared pointer
boost::shared_ptr<Lock> myLock; 
...
}
...
std::vector<DATA_MSG_PTR>& subscriptionInfo::getIncoming() {
    ReadLock Lock(myLock);
    return incoming;
}

and the error says:

error: no matching function for call to ‘boost::shared_lock<boost::shared_mutex>::shared_lock(boost::shared_ptr<boost::shared_mutex>&)’

I will appreciate if you help me find out what I messed up and how to solve it. thanks

4

1 回答 1

1

myLock成员是一个指针。一个聪明的,但在任何情况下都是一个指针。shared_lock构造函数接受对互斥对象的引用,而不是指针。这就是发生错误消息的原因。要解决问题,您必须将指针取消引用为ReadLock Lock(*myLock);

于 2013-03-25T13:07:16.990 回答