gpt4 book ai didi

c++ - = 函数声明后删除的含义

转载 作者:IT老高 更新时间:2023-10-28 11:26:28 25 4
gpt4 key购买 nike

class my_class
{
...
my_class(my_class const &) = delete;
...
};

= delete 在这种情况下是什么意思?

是否还有其他“修饰符”(= 0= delete 除外)?

最佳答案

删除函数是a C++11 feature :

The common idiom of "prohibiting copying" can now be expresseddirectly:

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

[...]

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

struct Z {
// ...

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

关于c++ - = 函数声明后删除的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5513881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com