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. including multiple headers

including multiple headers

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonhelpquestion
2 Posts 2 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.
  • W Offline
    W Offline
    wogerdoger
    wrote on last edited by
    #1

    Is it bad practice to have a "MyProjectHeaders.h" file that has the #ifndef......#endif protection around a set of include statements ? Then just include the "MyProjectHeaders.h" file in each source ? I know compilation/linking will take longer and there will be redundant headers. I played around with it and found that I had to include some specific headers in each source. The API includes do not seem to suffer from this (you can include an API header that has it's own include statements and access their functionality without including the specific file in the source). Can anyone shed some light on this ? Is it a VC++ 6.0 linking/settings issue ? Cheers ;-) If sex is a pain in the ass, then you are doing it all wrong!

    M 1 Reply Last reply
    0
    • W wogerdoger

      Is it bad practice to have a "MyProjectHeaders.h" file that has the #ifndef......#endif protection around a set of include statements ? Then just include the "MyProjectHeaders.h" file in each source ? I know compilation/linking will take longer and there will be redundant headers. I played around with it and found that I had to include some specific headers in each source. The API includes do not seem to suffer from this (you can include an API header that has it's own include statements and access their functionality without including the specific file in the source). Can anyone shed some light on this ? Is it a VC++ 6.0 linking/settings issue ? Cheers ;-) If sex is a pain in the ass, then you are doing it all wrong!

      M Offline
      M Offline
      Maximilien
      wrote on last edited by
      #2

      It's not bad practice, it's a good practice; better would be to remove the header dependency by using forward declaration, or pointer to objects in your classes instead of "direct" class members

      /// would be ok.
      ...
      #ifndef _A_CLASS_H_
      #include "AClass.h"
      #endif

      class CAnotherClass
      {
      CAClass m_AClass;
      }

      /// would be better.
      ...
      class CAClass;
      class CAnotherClass
      {
      CAClass* m_pAClass;
      }

      In the long run, including headers in cpp files will not be as costly as including them in header files ( see "Large Scale C++ Software Design" by Lakos ) if you need to include a file in another header file, you'd better use #ifndef ... #end around the include directive to limit the damages.


      Maximilien Lincourt "Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )

      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