函数后面加delete

The common idiom of "prohibiting copying" can now be expressed directly:

class X {
    // ...
    X& operator=(const X&) = delete;  // Disallow copying
    X(const X&) = delete;
};

[...]

The "delete" mechanism can be used for any function. For example, we can eliminate an undesired conversion like this:

struct Z {
    // ...

    Z(long long);     // can initialize with an long long         
    Z(long) = delete; // but not anything less
};

参考资料:
http://stackoverflow.com/questions/5513881/meaning-of-delete-after-function-declaration

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,900评论 0 23
  • 食指 邓伊彤 你的姿态, 虽然不如其它手指窈窕,但你的工作却很复杂。 你的曲线, 虽是直直...
    悦读生活阅读 509评论 0 0
  • 最近刷朋友圈,看着同学们发的状态,似乎多少也有迷茫的唏嘘感,为着自己的未来而担忧,又或者开始觉得自己一事无成,陷落...
    凌南絮阅读 508评论 4 4