在 StackOverflow 上查看,我发现在 Clang++ 上,当使用 C++11 标准时,如果您已经为您的类定义了一个移动构造函数,隐式构造函数生成将被禁用,即复制构造函数被“显式删除”。
有什么办法可以禁止这种行为吗?
此外,这种行为是否标准化?因为我在 GCC 中没有相同的行为。
最佳答案
Is there any way to disable this behavior?
没有。但您始终可以:
A(const A&) = default;
虽然我不确定 clang 目前是否完全实现了默认的复制构造函数。
Also, is this behavior standardized?
是的。 [class.copy]/p7:
If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; ...
...
Because I don't have the same behavior in GCC.
哪个版本?我猜想最新的 gcc 版本与 clang 具有相同的行为。但我没有它可供试验。
关于c++ - 在 Clang 上禁用 "deletion of copy constructor when move constructor is avaliable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8797820/