Thread: #include question

  1. #1
    Registered User
    Join Date
    Jan 2006

    #include question

    I want to include <string> in my main file, as well as a subfile that I included in my mainfile. However, I have noticed that if I #include it in both files, I pay for it twice in terms of EXE bulk.

    My question is how does one go about having access to strings in all the associated files, but without having to include it in each, which is silly? Is there any way to send includes "down the line"?

    I sort of hate to ask this, but all the C++ learning info seems to gloss over details like this, so answers are slim for this kind of question.
    Last edited by Goombaz; 01-08-2006 at 02:23 PM.

  2. #2
    Registered User
    Join Date
    Aug 2005
    you must be seeing some other behavior because including <string> in each *.cpp file will not, in itself, cause the executable to become larger with each *.cpp file that you add to the project. You can include <string> as many times as you desire with no change in executable size.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Including a header doesn't effect the size of an executable at all because headers contain only declarations and they don't produce any code..

  4. #4
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Manassas, VA USA
    make sure you are compiling your code in 'release' mode instead of 'debug' mode
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  5. #5
    The N00b That Owns You!
    Join Date
    Jul 2005
    also, normally you cant always include headers as much as you like if they dont have a "definition procedure"

    #ifndef HEADER_H
    #define HEADER_H
    // header code
    this is to prevent if a user adds the header twice youd get a error this means if its been included it defines HEADER_H if its been included again HEADER_H would already be defined so the whole header code would be void
    New Function!!!!


    The feeling of rusty spoons against my salad fingers is almost ORGASMIC

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Precompiled header question
    By donglee in forum C++ Programming
    Replies: 13
    Last Post: 01-22-2009, 01:23 AM
  2. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  3. Socket Question
    By DaveHope in forum Networking/Device Communication
    Replies: 12
    Last Post: 06-21-2005, 04:50 PM
  4. Headers that use each other
    By nickname_changed in forum C++ Programming
    Replies: 7
    Last Post: 10-03-2003, 04:25 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM