class my_class { ... my_class(my_class const &) = delete; ... };
在这种情况下是什么= delete意思?
= delete
是否有任何其他“修饰符”(除了= 0and = delete)?
= 0
删除函数是C++11 的一个特性:
“禁止复制”的常用成语现在可以直接表达: class X { // ... X& operator=(const X&) = delete; // Disallow copying X(const X&) = delete; }; […] “删除”机制可用于任何功能。例如,我们可以像这样消除不需要的转换: struct Z { // ... Z(long long); // can initialize with an long long Z(long) = delete; // but not anything less };
“禁止复制”的常用成语现在可以直接表达:
class X { // ... X& operator=(const X&) = delete; // Disallow copying X(const X&) = delete; };
[…]
“删除”机制可用于任何功能。例如,我们可以像这样消除不需要的转换:
struct Z { // ... Z(long long); // can initialize with an long long Z(long) = delete; // but not anything less };