错误:使用已删除的函数boost :: shared_mutex :: shared_mutex

时间:2015-11-10 12:36:14

标签: c++ gcc boost

这真的很奇怪。首先我不知道你可以删除函数,其次,这发生在外部库中。

错误的情况是我正在使用QtCreator来构建项目并一起提升,没有任何静态库。

使用的编译器是gcc

myprogram.h:4:7: error: use of deleted function 'boost::shared_mutex::shared_mutex(const boost::shared_mutex&)'
In file included from ../libs/boost155/boost/thread/lock_guard.hpp:11:0,
                 from ../libs/boost155/boost/thread/pthread/thread_data.hpp:11,
                 from ../libs/boost155/boost/thread/thread_only.hpp:17,
                 from ../libs/boost155/boost/thread/thread.hpp:12,
                 from ../libs/boost155/boost/thread.hpp:13,
                 from myprogram.h:2,
                 from myprogram.cpp:1:

2 个答案:

答案 0 :(得分:3)

您正在尝试复制互斥锁。这是不可能的。

你从

开始触发
shared_mutex

那就是你的代码。也许,如果你的代码中没有显式,那么你有一个struct MyClass { boost::shared_mutex sm; }; std::vector<MyClass> v; // etc. 作为一个类的成员,并且这个类被复制,作为其余代码的一部分。

E.g:

vector

SYSDATETIME将在许多操作过程中复制它的元素,这将在此过程中触发互斥锁副本。

背景:

答案 1 :(得分:0)

  

首先,我不知道你可以删除功能

C ++ 11允许:

struct noncopyable
{
  noncopyable(const noncopyable&) =delete;
  noncopyable& operator=(const noncopyable&) =delete;
};

另一个类似的功能是标记为默认的功能(=default)。关于已删除和默认功能的MSDN上的好文章:click

  

第二,这发生在外部库中。

您尝试从该库中复制shared_mutex - 这是不可能的。想一想 - &#34; mutex copy&#34;代表什么?

可能你有一些引入复制的代码 - 你在std::容器中存储了一些包含互斥的对象吗?