Liu
Liu

Reputation: 655

What is "= delete"?

What do these two strange lines of code mean?

thread_guard(thread_guard const&) = delete;

thread_guard& operator=(thread_guard const&) = delete;

Upvotes: 8

Views: 854

Answers (2)

kennytm
kennytm

Reputation: 523254

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.

Upvotes: 12

Naveen
Naveen

Reputation: 73443

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.

Upvotes: 10

Related Questions