mardi 16 août 2016

Getting Errors with "std_lib_facilities.h"

I'm doing exercises from Stroustrup's book. Here's the link of his solutions. I got errors if I included his header file.

enter image description here

$ clang++ --version
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/http://ift.tt/1z8WHIF

$ gcc --version
Configured with: --prefix=/Applications/http://ift.tt/1d5DwEL --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.3.0 (clang-703.0.31)
Target: x86_64-apple-darwin15.6.0
Thread model: posix
InstalledDir: /Applications/http://ift.tt/1z8WHIF

enter image description here

How can I upgrade to C++11? I've tried this:

clang++ -std=c++11 -stdlib=libc++ example.cpp

And I got:

$ clang++ -std=c++11 -stdlib=libc++ main.cpp
In file included from main.cpp:4:
In file included from ./std_lib_facilities.h:34:
/Applications/http://ift.tt/2bFr3QU: warning:
      Use of the header <ext/hash_map> is deprecated. Migrate to <unordered_map>
      [-W#warnings]
#   warning Use of the header <ext/hash_map> is deprecated.  Migrate to ...
    ^
In file included from main.cpp:4:
./std_lib_facilities.h:43:20: error: no matching function for call to object of
      type 'hash<char *>'
            return hash<char*>()(s.c_str());
                   ^~~~~~~~~~~~~
/Applications/http://ift.tt/2b3dVAK: note:
      candidate function not viable: 1st argument ('const value_type *'
      (aka 'const char *')) would lose const qualifier
    size_t operator()(char *__c) const _NOEXCEPT
           ^
In file included from main.cpp:4:
./std_lib_facilities.h:112:14: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
        if (i<0||size()<=i) throw Range_error(i);
            ~^~
./std_lib_facilities.h:118:14: warning: comparison of unsigned expression < 0 is
      always false [-Wtautological-compare]
        if (i<0||size()<=i) throw Range_error(i);
            ~^~
3 warnings and 1 error generated.

Here's the header file link.

Aucun commentaire:

Enregistrer un commentaire