c++ - Does include ? -
c++ - Does <algorithm> include <cmath>? -
the next programme compiles correctly:
#include <algorithm> int main(int argc, char *argv[]) { homecoming int(log(23.f)); }
(under g++ 4.9.2 flag -std=c++11
)
the code uses function log
, defined on <cmath>
. however, not include header <cmath>
, header <algorithm>
. why g++
doesn't give warnings, , compiles code correctly?
in c++11 standard, [res.on.headers]/1 states that
a c++ header may include other c++ headers. c++ header shall provide declarations , definitions appear in synopsis. a c++ header shown in synopsis including other c++ headers shall provide declarations , definitions appear in synopses of other headers.
now consider [algorithms.general]/2:
header<algorithm>
synopsis #include <initializer_list> namespace std { // ......
<cmath>
isn't listed , not included in <initializer_list>
. programme not guaranteed compile on standard-conforming implementation. 1 should never rely on "implicit inclusion" - general guideline include every header entity used. exceptions e.g. <iostream>
including <ostream>
, guaranteed since c++11.
c++ c++11 standards c++-standard-library
Comments
Post a Comment