DEV Community

Discussion on: How to Write a C++ Library

Collapse
 
pauljlucas profile image
Paul J. Lucas

By "self-sufficient", Xe means, local headers are not depending on System or External libraries.

That's not what I meant. They can depend on system of external libraries; but, if they do, they #include them themselves rather that rely on the file they're being included into.

If I have this:

// foo.h
class C {
    // ...
    std::string _s;
};
Enter fullscreen mode Exit fullscreen mode

and:

// bar.h
#include <string>
#include "foo.h"

void f( C const& );
Enter fullscreen mode Exit fullscreen mode

then this works by "accident." Even though foo.h uses std::string and foo.h does not #include <string>, it works because <string> is included by bar.h before it includes foo.h. However, if you change the includes in bar.h, you could break foo.h. So it foo.h wants std::string, it needs to #include <string> itself.

Collapse
 
ra101 profile image
Parth Agarwal • Edited

That is exactly, What i meant, Probably not worded correct tho...

local headers are not depending on System or External libraries. (of this file)

Thanks a lot tho,