gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:47:44 28 4
gpt4 key购买 nike

我正在处理这个线程 swap c++ map objects in multithreaded environment

但是,

#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"));
}

给出编译时错误

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++ 版本有关/c++/4.8.5/ 在另一个盒子上,都给出了同样的问题。我应该升级 C++ 版本吗?

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

最佳答案

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

关于c++ - 共享指针上的原子操作,C++ 版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56120936/

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