mardi 12 février 2019

no matching function for call to 'make_shared'

I am getting compiler error "no matching function for call to 'make_shared'" whenever I try to use a constructor that takes any arguments. So, for example:

std::shared_ptr<int> foo = std::make_shared<int> ();

works fine. But,

std::shared_ptr<int> foo = std::make_shared<int> (10);

Gives the following error:

/usr/bin/clang  -g -Wall -Wextra -Wc++11-extensions -c ./test.cpp
./test.cpp:7:30: error: no matching function for call to 'make_shared'
  std::shared_ptr<int> foo = std::make_shared<int> (10);
                         ^~~~~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4700:1: note: candidate function [with _Tp = int, _A0 = int]
  not viable: expects an l-value for 1st argument
make_shared(_A0& __a0)

I took the above code directly from here http://www.cplusplus.com/reference/memory/make_shared/ and that code runs fine on cpp.sh web site. I suspect that there is something wrong with my compiler set up. Running in iTerm on a macbook. Also, I get the same error even if I remove the various options to clang shown above. Any ideas? Is it possible that my header file for needs to be updated? It's from Sep 4 2015. Seems recent enough for C++11 to work.

Aucun commentaire:

Enregistrer un commentaire