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. Avoid includei in header files

Avoid includei in header files

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 Posts 2 Posters 1 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.
  • R Offline
    R Offline
    reza matinnejad
    wrote on last edited by
    #1

    Hi, I prefer not to include any header files in other header files as long as it is possible. But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file. I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types: struct st1; //correct Class C1; //correct Enum e1; //Incorrect

    T 1 Reply Last reply
    0
    • R reza matinnejad

      Hi, I prefer not to include any header files in other header files as long as it is possible. But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file. I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types: struct st1; //correct Class C1; //correct Enum e1; //Incorrect

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      is this a design question ? or just trying to inform somebody here ? if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work... so, to make it short, go with #includes withing headers, it's not bad to do so !

      [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

      R 1 Reply Last reply
      0
      • T toxcct

        is this a design question ? or just trying to inform somebody here ? if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work... so, to make it short, go with #includes withing headers, it's not bad to do so !

        [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

        R Offline
        R Offline
        reza matinnejad
        wrote on last edited by
        #3

        I am not sure, but I think it is a good idea to do such a thing. Actually I avoid making circular includes in this way.

        T 1 Reply Last reply
        0
        • R reza matinnejad

          I am not sure, but I think it is a good idea to do such a thing. Actually I avoid making circular includes in this way.

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          reza matinnejad wrote:

          I avoid making circular includes in this way

          this CANNOT happen, as long as you designed your headers correctly. there is a multiple includes exclusion system which tells for the header which it's defined in not to include it more than once... If you're using Visual Studio only, the following is good and prefered for performances. This is MS specific:

          //Beginning of the header file
          #pragma once

          //...remaining of your file...

          if your sources are portable on pultiple plateforms, then use the standard construction which works on any compiler (Visual C++ included):

          //Beginning of the header file
          #ifndef __YOUR_HEADER_FILE_H_INCLUDED__
          #define __YOUR_HEADER_FILE_H_INCLUDED__

          //...remaining of your file...

          #endif //At the very end of the file

          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          R 1 Reply Last reply
          0
          • T toxcct

            reza matinnejad wrote:

            I avoid making circular includes in this way

            this CANNOT happen, as long as you designed your headers correctly. there is a multiple includes exclusion system which tells for the header which it's defined in not to include it more than once... If you're using Visual Studio only, the following is good and prefered for performances. This is MS specific:

            //Beginning of the header file
            #pragma once

            //...remaining of your file...

            if your sources are portable on pultiple plateforms, then use the standard construction which works on any compiler (Visual C++ included):

            //Beginning of the header file
            #ifndef __YOUR_HEADER_FILE_H_INCLUDED__
            #define __YOUR_HEADER_FILE_H_INCLUDED__

            //...remaining of your file...

            #endif //At the very end of the file

            [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

            R Offline
            R Offline
            reza matinnejad
            wrote on last edited by
            #5

            Thank you :)

            T 1 Reply Last reply
            0
            • R reza matinnejad

              Thank you :)

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              ps, i didn't say it, because it was obvious to me, but you have to be careful that the macros such as "__YOUR_HEADER_FILE_H_INCLUDED__" is unique for each file (if 2 headers define the same macro, redefining identifiers errors may happen)...

              [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

              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