Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Proper way to include header files

Proper way to include header files

Scheduled Pinned Locked Moved C / C++ / MFC
c++comtoolshelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    georgiek50
    wrote on last edited by
    #1

    In regards to this thread (which I have yet to find a resolution) http://www.codeproject.com/script/comments/forums.asp?msg=851353&forumid=1647#xx851259xx I decided to strip away all header file includes from the code and compile the cpp files one by one in order to find the root of the problem. All my header files are enclosed in the #ifndef #define #endif statement and I include all necessary headers for a cpp file in a single header and along with other class and function definitions include that file... eg. MyFile.h -------- #ifndef MYFILE_H #define MYFILE_H #include "OtherHeaderFile.h" #include "OtherHeaderFile2.h" class { .... }; extern ... #endif MYFILE_H MyFile.cpp ---------- #include "MyFile.h" As I start going down the list of compiled files I run into the syntax errors (from files that compiled fine higher up in the list in the list; errors are in the header files) when header files include each other as in the previous thread I posted. What are the general rules of header inclusion...there is something crucial I seem to be missing as far as these rules are concerned. Can someone offer some advice?

    J J W 3 Replies Last reply
    0
    • G georgiek50

      In regards to this thread (which I have yet to find a resolution) http://www.codeproject.com/script/comments/forums.asp?msg=851353&forumid=1647#xx851259xx I decided to strip away all header file includes from the code and compile the cpp files one by one in order to find the root of the problem. All my header files are enclosed in the #ifndef #define #endif statement and I include all necessary headers for a cpp file in a single header and along with other class and function definitions include that file... eg. MyFile.h -------- #ifndef MYFILE_H #define MYFILE_H #include "OtherHeaderFile.h" #include "OtherHeaderFile2.h" class { .... }; extern ... #endif MYFILE_H MyFile.cpp ---------- #include "MyFile.h" As I start going down the list of compiled files I run into the syntax errors (from files that compiled fine higher up in the list in the list; errors are in the header files) when header files include each other as in the previous thread I posted. What are the general rules of header inclusion...there is something crucial I seem to be missing as far as these rules are concerned. Can someone offer some advice?

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      It is hard to say what the problem is without seeing all your files (and you certainly shouldn't post them all on here!) Just from the post above I am wondering what the 'extern' is for, why you are including OtherHeaderFile.h and OtherHeaderFile2.h, and what the errors are.

      G 1 Reply Last reply
      0
      • G georgiek50

        In regards to this thread (which I have yet to find a resolution) http://www.codeproject.com/script/comments/forums.asp?msg=851353&forumid=1647#xx851259xx I decided to strip away all header file includes from the code and compile the cpp files one by one in order to find the root of the problem. All my header files are enclosed in the #ifndef #define #endif statement and I include all necessary headers for a cpp file in a single header and along with other class and function definitions include that file... eg. MyFile.h -------- #ifndef MYFILE_H #define MYFILE_H #include "OtherHeaderFile.h" #include "OtherHeaderFile2.h" class { .... }; extern ... #endif MYFILE_H MyFile.cpp ---------- #include "MyFile.h" As I start going down the list of compiled files I run into the syntax errors (from files that compiled fine higher up in the list in the list; errors are in the header files) when header files include each other as in the previous thread I posted. What are the general rules of header inclusion...there is something crucial I seem to be missing as far as these rules are concerned. Can someone offer some advice?

        J Offline
        J Offline
        James R Twine
        wrote on last edited by
        #3

        Quick tip: look for missing semicolons at the end of struct/class defs, especially files that have no other code after the def.  Everytime I get non-obvious syntax errors early on in the compilation phase, that is the cause.    Peace! -=- James Tip for SUV winter driving survival: "Professional Driver on Closed Course" does not mean "your Dumb Ass on a Public Road"!
        Articles -- Products: Delete FXP Files & Check Favorites

        1 Reply Last reply
        0
        • G georgiek50

          In regards to this thread (which I have yet to find a resolution) http://www.codeproject.com/script/comments/forums.asp?msg=851353&forumid=1647#xx851259xx I decided to strip away all header file includes from the code and compile the cpp files one by one in order to find the root of the problem. All my header files are enclosed in the #ifndef #define #endif statement and I include all necessary headers for a cpp file in a single header and along with other class and function definitions include that file... eg. MyFile.h -------- #ifndef MYFILE_H #define MYFILE_H #include "OtherHeaderFile.h" #include "OtherHeaderFile2.h" class { .... }; extern ... #endif MYFILE_H MyFile.cpp ---------- #include "MyFile.h" As I start going down the list of compiled files I run into the syntax errors (from files that compiled fine higher up in the list in the list; errors are in the header files) when header files include each other as in the previous thread I posted. What are the general rules of header inclusion...there is something crucial I seem to be missing as far as these rules are concerned. Can someone offer some advice?

          W Offline
          W Offline
          Weiye Chen
          wrote on last edited by
          #4

          If you have a header file that will be included in many other source or header files, include it in stdafx.h Weiye Chen When pursuing your dreams, don't forget to enjoy your life...

          1 Reply Last reply
          0
          • J Johnny

            It is hard to say what the problem is without seeing all your files (and you certainly shouldn't post them all on here!) Just from the post above I am wondering what the 'extern' is for, why you are including OtherHeaderFile.h and OtherHeaderFile2.h, and what the errors are.

            G Offline
            G Offline
            georgiek50
            wrote on last edited by
            #5

            I use the extern in each header file for each global class object (all defined in another header file and included in only one cpp file) I am going to play around with the extern declarations to try and come up w/ a solution.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups