0

This is really weird. First I didn't know that you can delete functions and second, this happens in external library.

The circumstances of the error are that I'm using QtCreator to build project AND boost all together, without any static libs whatsoever.

The compiler used is 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:
Tomáš Zato
  • 50,171
  • 52
  • 268
  • 778

2 Answers2

4

You're trying to copy a mutex. That is not possible.

You're triggering that from

 from myprogram.h:2,
 from myprogram.cpp:1:

So, that's your code. Probably, if it is not explicit in your code, you have a shared_mutex as a member in a class, and this class is getting copied, somewhere as part of the rest of the code.

E.g.:

struct MyClass {
    boost::shared_mutex sm;
};

std::vector<MyClass> v;
// etc.

vector will copy.move its elements during many operations and this would trigger the mutex copy along the way.

For background:

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
  • Wow, you're good. I had the long initialisation of that class - `MyClass inst = MyClass()`. GCC probably treats this differently than MSVC and raises an error. I can't imagine I'd ever figure this myself. – Tomáš Zato Nov 10 '15 at 12:43
  • Call it experience :) Cheers. By the way: [copy initialization](http://en.cppreference.com/w/cpp/language/copy_initialization) (requires accessible copy-assignment operator, even if not used) – sehe Nov 10 '15 at 12:43
0

First I didn't know that you can delete functions

C++ 11 allows that:

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

Another similar feature are functions marked as default (=default). Good article on MSDN about deleted and defaulted functions: click.

second, this happens in external library.

You try to copy shared_mutex from that library - that is not possible. Think about it - what would "mutex copy" represent?

Probably you have some code, that introduces copying - do you store some objects containing mutexes in std:: containers?

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49