CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2010
    Location
    Minnesota, United States
    Posts
    12

    Question to many include files

    Hello,

    I am trying to compile a program but it keeps giving me this error message.
    fatal error C1014: too many include files : depth = 1024
    Attached Files Attached Files

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: to many include files

    I didn't actually inspect the files you attached, but the error you get suspiciously looks like the two .h files (or any other two .h files) are including each other mutually and don't contain #include guards or #pragma once directives. Could that be the case?

    BTW, mutual inclusion often is a sign of bad design and can indicate problems (maybe still to come) aside from this error message.

    HTH

    Ah, and... Welcome to CodeGuru!
    Last edited by Eri523; December 23rd, 2010 at 07:51 PM.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Apr 2008
    Posts
    725

    Re: to many include files

    IFDEF guards are there, just in the wrong place. Header guards need to be the very first things in the file. not the first thing after other includes.

  4. #4
    Join Date
    Dec 2010
    Location
    Minnesota, United States
    Posts
    12

    Re: to many include files

    I put the #include statements inside of the #ifndef - #endif blocks, but when I do this the compiler no longer recognizes #include statements.
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: to many include files

    The problem is the circular inclusion, as Eri523 suspected: ParkingTicket_h.h includes PoliceOfficer_h.h which includes ParkingTicket_h. Placing the entire header within those include guards is correct, but will not solve this problem.

    Observe that ParkingTicket has a PoliceOfficer member variable. Therefore, ParkingTicket needs the definition of PoliceOfficer, so you should include PoliceOfficer_h.h in ParkingTicket_h.h. But PoliceOfficer only has member functions that need ParkingTicket, so a forward declaration of ParkingTicket will suffice in PoliceOfficer_h.h. You can include ParkingTicket_h.h in the source file that implements the PoliceOfficer class.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Dec 2010
    Location
    Minnesota, United States
    Posts
    12

    Smile Re: to many include files

    I put the #includes inside of the #ifndef-#endif blocks and added forward declarations and now the program works!

    Thanks every one for your help with this problem.

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