Thread: Style issue?

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    15

    Style issue?

    Rogster brought this up in my other thread (by accident as he doesn't know why I do this):

    Is it ok to put all your #includes in your header files?

    When I have multiple objects referencing each other I put all the #include's in the 'top' one (ie/ the one which must be #include'd by the most other obj's) working 'down' through the header files and only #include'ing somethign if it is neccessary at that 'level' of my header-include heirachy.

    Is this bad as far as performance goes? What is the 'best' way to #include things?

    I know there's no code here but maybe there is a better way (I don't ever #pragma, as I like to keep stuff under my control) to maintain a 'tidy' style out there.

    Morb

  2. #2
    Registered User
    Join Date
    Nov 2010
    Posts
    15
    obviously you must #include the header files which contain the relavent #includes, owch....

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    If I only need a forward declaration of a class in a header, I would rather write out that forward declaration in my header than include the header that contains the definition of that class.

    Quote Originally Posted by morbidslug
    Is this bad as far as performance goes? What is the 'best' way to #include things?
    The performance thing is only a compile-time issue: when a header file is changed, all source files that include that header should be re-compiled. So, if you have a universal header file that includes pretty much all other headers, then you would typically end up re-compiling all your source files if any header file is changed, when it may be the case that you just need to re-compile one or two source files.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Nov 2010
    Posts
    15
    Beautiful, cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  4. WS_EX_COMPOSITED style (double buffering) problems
    By JasonD in forum Windows Programming
    Replies: 2
    Last Post: 10-12-2004, 11:21 AM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM