Open1

『C++によるプログラミングの原則と実践』を読む

nabeyangnabeyang

ハローワールドで早速、エラーが出る

$ clang++ main.cpp -std=c++11   
In file included from main.cpp:1:
./std_lib_facilities.h:49:8: error: unknown type name 'ios_base'; did you mean 'std::ios_base'?
inline ios_base& defaultfloat(ios_base& b)      // to augment fixed and scientific as in C++11
       ^~~~~~~~
       std::ios_base
/Applications/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:243:24: note: 'std::ios_base' declared here
class _LIBCPP_TYPE_VIS ios_base
                       ^
In file included from main.cpp:1:
./std_lib_facilities.h:49:31: error: unknown type name 'ios_base'
inline ios_base& defaultfloat(ios_base& b)      // to augment fixed and scientific as in C++11
                              ^
./std_lib_facilities.h:51:9: error: use of undeclared identifier 'ios_base'; did you mean 'std::ios_base'?
        b.setf(ios_base::fmtflags(0), ios_base::floatfield);
               ^~~~~~~~
               std::ios_base
/Applications/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:243:24: note: 'std::ios_base' declared here
class _LIBCPP_TYPE_VIS ios_base
                       ^
In file included from main.cpp:1:
./std_lib_facilities.h:51:32: error: use of undeclared identifier 'ios_base'; did you mean 'std::ios_base'?
        b.setf(ios_base::fmtflags(0), ios_base::floatfield);
                                      ^~~~~~~~
                                      std::ios_base
/Applications/Xcode-15.2.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:243:24: note: 'std::ios_base' declared here
class _LIBCPP_TYPE_VIS ios_base
                       ^

ios_basestd::ios_baseにするとコンパイルできる。ただ、-std=c++11を付けないとエラーになる。

$ clang++ main.cpp
In file included from main.cpp:1:
./std_lib_facilities.h:57:17: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Unicode = long;
                ^
./std_lib_facilities.h:78:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
        using size_type = typename std::vector<T>::size_type;
                          ^
./std_lib_facilities.h:109:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
        using size_type = std::string::size_type;
                          ^
./std_lib_facilities.h:226:74: error: expected '(' for function-style cast or type construction
inline int randint(int min, int max) {  return uniform_int_distribution<>{min, max}(get_rand()); }
                                               ~~~~~~~~~~~~~~~~~~~~~~~~~~^
./std_lib_facilities.h:235:20: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Value_type = typename C::value_type;
                   ^
./std_lib_facilities.h:238:18: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
using Iterator = typename C::iterator;
                 ^