struct S
{
int x;
int y;
};
std::atomic<S> asd{{1, 2}}; // what should this be? This doesn't work
编辑:在g++中,
{{1, 2}}
和({1, 2})
都能正常工作,但在clang中却不能。是否有clang的解决方法?struct S
{
int x;
int y;
};
std::atomic<S> asd{{1, 2}}; // what should this be? This doesn't work
{{1, 2}}
和({1, 2})
都能正常工作,但在clang中却不能。是否有clang的解决方法?atomic<T>
中的T
标量类型。C++11标准明确规定(§29.5/1),T
可以是任何平凡可复制的类型。constexpr atomic(T) noexcept;
atomic<S>
,然后使用 atomic::store
来初始化对象。std::atomic<S> asd;
asd.store({1,2});
std::atomic<S> asd({1, 2});
std::atomic<S>
有一个构造函数,它接受类型为S的值。
由于这个构造函数,初始化列表{1, 2}被隐式转换为临时S。
clang++
上也无法编译。但是两个版本都可以在 g++
上编译。 - vsoftcostd::atomic<S> asd(S{1,2});
。顺便问一下,你使用的是哪个版本的clang? - axnsan