Appropriate header file

This is a discussion on Appropriate header file within the C++ Programming forums, part of the General Programming Boards category; I'm working on a relatively large project that is split into multiple files of source code/.cpp files (for better readability). ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    43

    Appropriate header file

    I'm working on a relatively large project that is split into multiple files of source code/.cpp files (for better readability).
    The overall code should be in compliance with the standards, but I'm afraid I'm not familiar with the C++ header files.
    Note that I do the following in front of main():
    Code:
    #include <iostream>
    #include <math.h>
    #include <vector>
    #include "one.cpp"
    #include "two.cpp"
    #include "three.cpp"
    
    int main() {
    ....
    }
    Then, I made a .h file, myHeader.h, that looks like this:
    Code:
    #ifndef MYHEADER_H
    #define MYHEADER_H
    #include <iostream>
    #include <math.h>
    #include <vector>
    #include "one.cpp"
    #include "two.cpp"
    #include "three.cpp
    #endif
    In the main file, I only have "#include "myHeader.h" before the main(). Is this fine and
    in compliance with the standards?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by onako View Post
    Is this fine and
    in compliance with the standards?
    in compliance with the standards, yes. Fine... Depends on what you call fine. I think the code becomes less readable by doing such a thing, and compiling will definitely take longer... I recommend just adding all dependencies of one file in that file, and no others.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    43
    Thanks for the reply.
    Are you suggesting to move all the cpp file into one large code fragment before main(), and
    forget about the headers?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Erm... No. I'm suggesting to have the list of includes required for each file in that file itself.

  5. #5
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    Quote Originally Posted by onako View Post
    Thanks for the reply.
    Are you suggesting to move all the cpp file into one large code fragment before main(), and
    forget about the headers?
    Do not include cpp at all
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by vart View Post
    Do not include cpp at all
    Ahhh, lol, I missed the point that those files where cpp files, I thought they were header files.

    In that case, I completely agree with vart. Make a header file and include that, then compile the CPP files separately and link them together.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Replies: 30
    Last Post: 06-19-2006, 12:35 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM

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