加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 什么是“=删除”?

发布时间:2020-12-16 04:55:42 所属栏目:百科 来源:网络整理
导读:这两行奇怪的代码是什么意思? thread_guard(thread_guard const) = delete;thread_guard operator=(thread_guard const) = delete; 解决方法 = delete是C 0x的新功能.这意味着一旦用户使用这样的函数,编译器应立即停止编译并抱怨“此函数被删除”(参见:Bja
这两行奇怪的代码是什么意思?
thread_guard(thread_guard const&) = delete;

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

解决方法

= delete是C 0x的新功能.这意味着一旦用户使用这样的函数,编译器应立即停止编译并抱怨“此函数被删除”(参见:Bjarne Stroustrup的C 0x FAQ的 defaulted and deleted functions — control of defaults).

thread_guard(thread_guard const&)是一个复制构造函数,thread_guard& operator =(thread_guard const&)是赋值构造函数.因此,这两行一起禁用了thread_guard实例的复制.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读