CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 1999
    Posts
    1

    Question: Nested Headers or Headers in Headers

    Can anybody tell me why it would be bad to include headers within other headers? Where I work it's policy, but I believe that if we take the simple precaution of using the

    #ifndef _HEADER_XXXX_
    #define _HEADER_XXXX_
    #endif




    construct, there would be no problems and it would simplify including, say, a class that needed certain structures. As long as you only include what you NEED, there should be no problems.

    And it would save having to include headers with the structures the class needs before including the class, in EVERY c file that uses that class.

    So if any one can come up with a case where including headers within headers causes problems that wouldn't be present if not the case, please let me know. Whether they be managability, compile problems, etc. (And where every header includes the above construct, and that inclusion is done above braindead level)


    Thanks for your help




  2. #2
    Join Date
    May 1999
    Location
    Texas, USA
    Posts
    568

    Re: Question: Nested Headers or Headers in Headers

    I agree with you. That is stupid policy as long as you are only including the header file once. To me it is much easier, if needed, to include the file in the header file.
    #ifndef _SOME_FILE
    #define _SOME_FILE

    #include "SomeOtherClass.h"

    class SomeClass
    {
    CSomeOtherClass m_Class;
    }
    #endif



    In this case it makes sense to include the file in the header file. But if you reference the class only in the CPP file, then only include the header file in the CPP file. In other words, I agree with you.

    Wayne



  3. #3
    Guest

    Re: Question: Nested Headers or Headers in Headers

    #ifndef __H_HUMBLE
    #define __H_HUMBLE



    FWIW, I worked on a project in the mid '80s where a similar "no nested headers" policy was used. It turned out that the primitive CM tools we used for source code control goofed up the dependency tree if headers were nested. Maybe this is an anachronism from days gone by?

    Also, if this is such a *bad thing*, why did the compiler gods create the "#pragma once" statement?

    Cheers!
    Humble Programmer
    ,,,^..^,,,

    #endif




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured