gpt4 book ai didi

c++ - 为什么抛出的对象必须进行复制初始化?

转载 作者:可可西里 更新时间:2023-11-01 17:05:08 25 4
gpt4 key购买 nike

异常使用对象的静态类型来复制初始化抛出的对象。例如:

struct foo
{
foo() = default;
foo(const foo&) = delete;
};

int main()
{
throw foo();
}

Clang++ --std=c++14 提示无法使用显式删除的复制构造函数。为什么它不能移动初始化呢?

最佳答案

它不能移动构造,因为该类型没有移动构造函数。删除的复制构造函数会抑制隐式移动构造函数。

关于c++ - 为什么抛出的对象必须进行复制初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33111800/

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