0

I'm making some header files that I'll be using, so far I have 4, which are named: name.h patrons.h library.h and book.h. My problem is this: library.h contains a book object which is found in the book.h class. patrons.h contains objects found in the book.h class. So most if not all of the class interact with each other in some way.

When I try to compile the header files I get this error:

patrons.h:12:20: error: #include nested too deeply
patrons.h:13:18: error: #include nested too deeply
patrons.h:14:19: error: #include nested too deeply
patrons.h:15:18: error: #include nested too deeply
patrons.h:16:21: error: #include nested too deeply
patrons.h:17:18: error: #include nested too deeply
In file included from name.h:18:0,
                 from library.h:16,

and this loops through and gives me the identical error for each file. I assume this is because the book.h has an #include "library.h and so does patrons.h, so it causes a loop of some sorts. How do I fix this? I'm new to C++ so please excuse me if it is hard to understand.

iamtesla
  • 423
  • 2
  • 5
  • 18
  • 1
    http://stackoverflow.com/questions/6021720/c-nested-include-avoiding-include-nested-too-deeply-error – Mikołaj Mularczyk Oct 01 '14 at 21:56
  • Instead of including other headers in header files, you should forward declare referenced classes and structs as much as possible, and include the headers with the full declaration in your translation units (.cpp files). – πάντα ῥεῖ Oct 01 '14 at 21:59
  • @MikołajMularczyk Thanks, that fixes that. I have some `enum` and other `define` included in the header file. I am now getting the error that they're `not declared in that scope` even though the header file it is linked to contains the definitions. Is there a way to make this definitions `public`? – iamtesla Oct 01 '14 at 22:03

0 Answers0