LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2002, 02:22 PM   #1
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Rep: Reputation: 15
#include <spaghetti>


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!
 
Old 09-03-2002, 03:42 PM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
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

Or do I understand your question wrong?

Last edited by Hko; 09-03-2002 at 03:45 PM.
 
Old 09-03-2002, 04:43 PM   #3
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Original Poster
Rep: Reputation: 15
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.
 
Old 09-03-2002, 05:57 PM   #4
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 398

Rep: Reputation: 87
Yip, that is a fact of life. The only solution (not partticularly wonderful) is the pimpl idiom. Google is your friend to find out more.
 
Old 09-04-2002, 08:38 AM   #5
boku
Member
 
Registered: Aug 2002
Location: Sweden
Distribution: Gentoo
Posts: 43

Original Poster
Rep: Reputation: 15
Thanks! After reading a bit about pimpl I understand why many use C and not C++.
 
Old 09-04-2002, 04:01 PM   #6
cyent
Member
 
Registered: Aug 2001
Location: ChristChurch New Zealand
Distribution: Ubuntu
Posts: 398

Rep: Reputation: 87
Nope. Using C won't help you. In fact the problem comes from C++'s C roots.

I think it is all just a run time optimization tweak. Thus when you say...
myFunc()
{
MyHairyClass mhc;
}

The compiler can emit an immediate value for the sizeof(MyHairyClass) which is more effcient than loading in a linked in value. That's my guess.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
include/linux/types.h and include/linux/posix_types.h kpachopoulos Programming 2 11-26-2005 05:52 AM
Help for C++ include harrylee2003 Programming 3 09-28-2005 05:01 PM
php include msound Programming 2 06-24-2004 04:21 PM
include function phil81 Linux - Newbie 12 06-21-2003 04:40 AM
X include files evian Linux - General 6 03-25-2003 03:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration