Style issue?

This is a discussion on Style issue? within the C++ Programming forums, part of the General Programming Boards category; Rogster brought this up in my other thread (by accident as he doesn't know why I do this): Is it ...

  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
    22,302
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    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, 05:56 AM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 09: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, 12:21 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21