Reputation: 417
I was working on this thread swap c++ map objects in multithreaded environment
However,
#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"));
}
gives a compile time error
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
I did see a few threads on this problem and understand that it could be related to C++ version I have /usr/include/c++/4.2.1/
and /usr/include/c++/4.8.5/
on another box, both give the same issue. Should I upgrade the C++ version?
I resolved this issue by passing -std=c++11 flag.
Upvotes: 1
Views: 611
Reputation: 51842
It compiles fine here with GCC 8.3 and Clang 8.0, so yes, you should upgrade your compiler.
Upvotes: 0