Thread: Selective #include's

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    28

    Selective #include's

    Anyone know if there is a way to include only part of a header file, and part of the c++ file? Say for example I want 1 class structure and definitions from a header file/c++ file, but I don't want the other stuff in that header file. Any way to get just that one thing, without getting the rest of it?

    If I get all of it, it makes me include a lot of other files I don't want, because some of the other classes/functions require them. But the one class I want does not.
    -Grunt (Malek)

  2. #2
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    Nope, if you include a header, you get everything in it whether you want it or not. If all of the extra stuff bloats up your program a lot then you should complain to the maker of the library so they can fix it in further updates.

  3. #3
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I understand what you're saying. It doesn't feel right to include a whole library just for one function or class if it includes so much other code. Unfortunately, there is no way that I know of to include only part of a file. Your profile says you're a student, so if you're just writing programs for a class, I wouldn't worry about includes. If time/space constrictions are truly paramount, though, you could create a file and put only what you need in that file. It'd be a good deal of copying and pasting, rather time consuming. Truthfully, I would not worry about it too much. Unless you're coding a professional grade program, it's very unlikely that there will be any noticeable difference.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    If you want you can change the header to only include what you want:
    Code:
    #ifndef EXCLUDE_STUFF
    
       //Stuff
    
    #endif
    
    #ifndef EXCLUDE_THINGS
    
       /Things
    
    #endif
    
    #ifndef EXCLUDE_YADA
    
       //Yada
    
    #endif
    Then in your program:
    Code:
    #define EXCLUDE_THINGS
    
    ...
    If you don't want Things to be in your program.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Open to suggestions Brighteyes's Avatar
    Join Date
    Mar 2003
    Posts
    204
    If you want you can change the header to only include what you want:
    But be real careful when you change headers that you don't make, you never know what kind of coupling is used and conditionally compiling out parts could easily make something you want fail.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Includes making me insane >.<
    By IceDane in forum C Programming
    Replies: 14
    Last Post: 04-14-2008, 10:24 AM
  2. Makefile and includes
    By Lang in forum C Programming
    Replies: 4
    Last Post: 03-18-2008, 03:29 AM
  3. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  4. Why are using declarations passed over but not includes
    By indigo0086 in forum C++ Programming
    Replies: 7
    Last Post: 12-18-2006, 11:54 AM
  5. Circular includes
    By ventolin in forum C++ Programming
    Replies: 2
    Last Post: 05-23-2004, 05:43 PM