ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
All right, this is the snag. My class, foo, has private members of the type std::string, but most other parts of the program (which need foo), are very happy to go without these type of strings. But since interface and implementation usually share header file, all files that #include foo.h also need to #include <string>.
I've bothered myself about this common(?) issue for a while, and even played dirty tricks by hiding all private declarations with preprocessor #ifdefs. So I ask you, honourable gurus, to lend any guidance or comments on this!
After preprocessing foo.h, string.h becomes part of foo.h for it's #included in it. So when the implementation file (say foo.cpp) #includes foo.h it "inherits" all the headers #included in foo.h
Yea, that's how I usually do it. And I'm a little shy to depart from established practice.
Well, I guess this is the prevalent way - that each header file sorts out its own dependencies. I just think it is a bit contaminating, since only the implementation needs direct access to the private declarations of its own header file.
Don't get me wrong. This is not a big deal. It's just an interesting aspect of the way C/C++ is designed. Perhaps this is more of a linguistic question.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.