函数后面加delete

2017-01-24  本文已影响0人  麦兜胖胖次

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

上一篇 下一篇

猜你喜欢

热点阅读