开发者

What is "= delete"?

What do the开发者_运维技巧se two strange lines of code mean?

thread_guard(thread_guard const&) = delete;

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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜