首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >共享指针上的原子操作,c++版本

共享指针上的原子操作,c++版本
EN

Stack Overflow用户
提问于 2019-05-14 07:07:49
回答 2查看 386关注 0票数 1

我当时正在写这个帖子swap c++ map objects in multithreaded environment

然而,

代码语言:javascript
运行
复制
#include <memory>
#include <thread>
#include <chrono>
#include <atomic>
#include <iostream>
using namespace std;

shared_ptr<std::string> the_string;

int main()
{
     atomic_store(&the_string, std::make_shared<std::string>("first string"));
}     

给出编译时错误

代码语言:javascript
运行
复制
error: no matching function for call to 'atomic_store'
     atomic_store(&the_string, std::make_shared<std::string>("first string"));
     ^~~~~~~~~~~~
/Library/Developer/CommandLineTools/usr/include/c++/v1/atomic:1165:1: note: candidate template ignored: could not match 'atomic' against 'shared_ptr'
atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT

我确实看到了一些关于这个问题的帖子,并理解它可能与我在另一个盒子上的/usr/include/c++/4.2.1//usr/include/c++/4.8.5/的C++版本有关,这两个都给出了相同的问题。我应该升级C++版本吗?

我通过传递-std=c++11标志解决了这个问题。

EN

回答 2

Stack Overflow用户

发布于 2019-05-15 04:46:38

我通过传递标志-std=c++11解决了这个问题

票数 1
EN

Stack Overflow用户

发布于 2019-05-14 07:15:32

它可以在这里用GCC 8.3和Clang 8.0编译得很好,所以是的,你应该升级你的编译器。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56120936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档