Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
like image 487
Liu Avatar asked Sep 13 '10 09:09

Liu


People also ask

What do you mean by delete?

to strike out or remove (something written or printed); cancel; erase; expunge.

What is delete in computer?

Deleting a file removes it from the location where it is stored. If the storage location is your hard disk, the file is moved to the Recycle Bin. If the storage location is a disk, CD, or network location, the file is destroyed.

Why delete is used?

The delete feature is used to remove documents, pictures, and other files used by programs on your computer.


1 Answers

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.

like image 156
kennytm Avatar answered Oct 10 '22 05:10

kennytm