including headers

This is a discussion on including headers within the C++ Programming forums, part of the General Programming Boards category; Hi all, At this point in my C++ life, it seems easy to create a header, in which i put ...

  1. #1
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355

    including headers

    Hi all,

    At this point in my C++ life, it seems easy to create a header, in which i put not only definitions and such, but also my other includes.

    i.e.

    main CPP
    Code:
    #include "includedh.h"
    header
    Code:
    #include <iostream>
    #include <ctime>
    other CPP
    Code:
    #include "includedh.h"
    Is this a bad thing to do? If so, why?
    Thor's self help tip:
    Maybe a neighbor is tossing leaf clippings on your lawn, looking at your woman, or harboring desires regarding your longboat. You enslave his children, set his house on fire. He shall not bother you again.

    OS: Windows XP
    Compiler: MSVC

  2. #2
    Registered User
    Join Date
    Feb 2003
    Posts
    595
    Bad idea. It makes the program files less convenient to read by requiring the reader to refer to another file -- included.h -- to find out what was included.

    Also, you will always have to have the appropriate "included.h" file in the same directory with your main program. Presumably you will have many different "included.h" files, corresponding to various main programs. How will you distinguish one from the other? How do you keep track of which "included.h" goes with which main program.

    Or, if you are planning to use the same "included.h" with all of your programs, that's even worse. It means that in many programs you will be including things that didn't need to be included, which means your compiled programs will be bigger than necessary. Furthermore, this is likely to cause conflicts.

  3. #3
    Grammar Police HybridM's Avatar
    Join Date
    Jan 2003
    Posts
    355
    Thanks for the reply,

    I don't do this, i was just curious as to why nobody does.

    As to your second point, "includedh.h" was an example name, i wouldn't use a generic name like that. And i definately wouldn't use the same header for different programs.

    Your first point is reason enough, i should encourage good habits for when my programs become larger.

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. including headers and forward declaration
    By l2u in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2007, 03:47 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. problems with including headers
    By l2u in forum C++ Programming
    Replies: 3
    Last Post: 07-23-2006, 09:06 AM
  5. including headers inside headers
    By kromozom in forum C++ Programming
    Replies: 5
    Last Post: 04-18-2005, 11:56 AM

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