开发者

initialization of atomic variables in c++0x

Can atomic variables in c++0x be initialized globally?

For e.g.

atomic_int turnX = 5;
i开发者_开发百科nt main(){
    ....
}

fails with error: deleted function ‘std::atomic::atomic(const std::atomic&)’

looking at atomic_2.h does give an idea that this is not allowed. Am I correct in making a statement that atomic variables can be assigned values only from within a function?


try:

atomic_int turnX(5);

This is a constexpr constructor so it should be constructed as constant initialization (i.e. at load time).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜