【发布时间】:2022-01-06 21:45:20
【问题描述】:
我正在为我的课程编写工厂,但编译时遇到问题
struct A {
std::atomic_bool flag{}; // remove this, there would be no error
A() = default;
};
struct B {};
using base = std::variant<A, B>;
base create() {
return A();
}
我得到了错误:
error: could not convert 'A()' from 'A' to 'base{aka std::variant<A, B>}'
return A();
为什么会这样?如果我在A 中删除std::atomic_bool 为什么会起作用?
【问题讨论】:
-
原子不可复制
-
std::atomic不可复制,因此您也无法复制A