Hi,

> How does putting your own header at the top (vs. ~the bottom) help ensure
> "a header file always includes all symbols it requires”?


Given an incomplete header

    // foo.hpp
    std::string f();

    // foo.cpp
    #include “foo.hpp”
    #include <string>
    
    std::string f() { return {}; }

I get

    % clang++ -fsyntax-only foo.cpp --std=c++11
    In file included from foo.cpp:1:
    ./foo.hpp:1:1: error: use of undeclared identifier 'std'
    std::string f();
    ^
    1 error generated.

Swapping the include order makes this pass as `#include` is just textual 
replacement, and the `#include <string>` in `foo.cpp` would declare the symbol 
used in `foo.hpp`.


Cheers,

Benjamin

Reply via email to