8

What do these two strange lines of code mean?

thread_guard(thread_guard const&) = delete;

thread_guard& operator=(thread_guard const&) = delete;
Liu
  • 645
  • 2
  • 8
  • 16

2 Answers2

12

The =delete is a new feature of C++0x. It means the compiler should immediately stop compiling and complain "this function is deleted" once the user use such function (See also: defaulted and deleted functions -- control of defaults of the C++0x FAQ by Bjarne Stroustrup).

The thread_guard(thread_guard const&) is a copy constructor, and thread_guard& operator=(thread_guard const&) is an assignment constructor. These two lines together therefore disables copying of the thread_guard instances.

kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • 1
    Almost. The "use" of a deleted function in an unevaluated context (for example, as expression to `decltype`) can qualify as a template argument deduction failure. This makes a compiler just ignore a template. It doesn't make the compiler stop compiling. – sellibitze Sep 13 '10 at 20:34
10

It is the new C++0x syntax for disabling the certain functions of the class. See wikipedia for an example. Here you are telling that class thread_guard is neither copyable nor assignable.

Naveen
  • 74,600
  • 47
  • 176
  • 233