I want to define a vector with boost::mutex like :
boost::mutex myMutex ;
std::vector< boost::mutex > mutexVec;
mutexVec.push_back(myMutex);
But, I got error on Linux:
/boost_1_45_0v/include/boost/thread/pthread/mutex.hpp:33: error: âboost::mutex::mutex(const boost::mutex&)â is private /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:104: error: within this context
I cannot find a solution by searching online.
thanks
You could use a boost pointer container:
#include <boost/thread.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
boost::ptr_vector<boost::mutex> pv;
pv.push_back(new boost::mutex);
A ptr_vector takes ownership of its pointers so that they are deleted when appropriate without any of the overhead a smart pointer might introduce.
The copy constructor is private. You aren't supposed to copy a mutex.
Instead use:
boost::mutex *myMutex = new boost::mutex();
std::vector< boost::mutex *> mutexVec;
mutexVec.push_back(myMutex);
and if you don't want to manage the memory yourself use a boost::shared_ptr<boost::mutex>
instead of boost::mutex*
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