Thread: Including "Groups" of Libraries

  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    7

    Including "Groups" of Libraries

    Hi There!

    I am lazy and most of the time when adding certain functions to my programs, I always have to remind myself to include a certain header.

    Is there just a 'lazy' and 'customizable' way to include a bunch of headers into one header? For example:

    Code:
    #include "Group.h"
    Inside of Group.h would be...
    Code:
    #include <iostream.h>
    #include <time.h>
    #include <cstdlib>
    #include <conio.h>
    ...
    And about tons of other headers I will decide to use. Thanks for your responses if you do respond!

  2. #2
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Nothing wrong with that.

    When in doubt, try it =).

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You can, but you shouldn't.

    One of the hardest things to overcome is deciding at some later date that you want to re-use some of the code in another project, only to find that you have lots of useless dependencies which take far longer to pick apart than any time saved in keeping the code tight in the first place.

    Also, you end up using things you shouldn't, just because it happens to compile. If you got an error message instead, it might prompt you to think about the interface you're about to break, rather than blindly breaking it anyway.

    Not only that, if you have a useless dependency, then you'll trigger lots of useless recompilations as well, when you change a header you don't actually need (but include anyway for "convenience").

    You certainly don't want to mix header files from different languages / eras, like this
    #include <iostream.h> // old C++
    #include <time.h> // old C
    #include <cstdlib> // new C++ header for old C
    #include <conio.h> // ancient DOS header


    One thing you must NEVER do is put something like
    using namespace std;
    in a header file. Doing so breaks any code which attempts to use namespaces later on, as there is no way to undo a "using" clause.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    May 2008
    Posts
    7
    Great. Thanks a whole bunch! You are right though, mixing ancient headers and modern headers isn't exactly a good idea. I never planned on adding namespace to that 'all header' but thanks for the heads up.

    It would be better to know individually what headers go with what functions, just to improve that function sense sort of thing. Thanks for your help!

    EDIT: lol I just got it, "God of the C" that's funny. Next thing youll know it'll be "CBiscuit".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  3. Including Libraries
    By NotRegisterd;) in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2003, 09:06 PM
  4. (printf VS cout) and (including libraries)
    By \cFallen in forum C++ Programming
    Replies: 3
    Last Post: 01-20-2003, 09:47 PM
  5. Including libraries
    By Unregistered in forum Game Programming
    Replies: 1
    Last Post: 07-28-2002, 07:57 PM