我想用 boost::mutex 定义一个 vector ,例如:
boost::mutex myMutex ;
std::vector< boost::mutex > mutexVec;
mutexVec.push_back(myMutex);
但是,我在 Linux 上遇到错误:
/boost_1_45_0v/include/boost/thread/pthread/mutex.hpp:33: 错误:“boost::mutex::mutex(const boost::mutex&)”是私有(private)的 /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/ext/new_allocator.h:104: 错误:在此上下文中
我在网上搜索找不到解决方案。
谢谢
最佳答案
你可以使用一个 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);
ptr_vector 拥有其指针的所有权,以便在适当的时候删除它们,而不会产生智能指针可能引入的任何开销。
关于c++ - 如何在 C++ 中定义 vector <boost::mutex>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252909/