我当时正在写这个帖子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++/4.8.5/
的C++版本有关,这两个都给出了相同的问题。我应该升级C++版本吗?
我通过传递-std=c++11标志解决了这个问题。
发布于 2019-05-15 04:46:38
我通过传递标志-std=c++11解决了这个问题
发布于 2019-05-14 07:15:32
它可以在这里用GCC 8.3和Clang 8.0编译得很好,所以是的,你应该升级你的编译器。
https://stackoverflow.com/questions/56120936
复制相似问题