5

if I include class definition file classA.h in classB.h and classC.h, then if classD.h includes both classB.h and classC.h, will there be a class redefinition?

P Shved
  • 96,026
  • 17
  • 121
  • 165
Rn2dy
  • 4,112
  • 12
  • 43
  • 59
  • 2
    I'm pretty sure you just [asked this](http://stackoverflow.com/questions/4917488/c-include-header-problem). – Maxpm Feb 07 '11 at 01:44

1 Answers1

5

Provided that you correctly use include guards, this shouldn't be a problem. In particular, if you ensure that #include-ing the same file twice is idempotent (#include-ing the same header twice is the same as #include-ing it once), then this won't cause a problem. When classD.h includes classB.h, it will include classA.h. When it then tries to include classC.h and classC.h tries to include classA.h, then nothing happens. This is fine, though, because classC.h can see classA.h because it was already included.

MSalters
  • 173,980
  • 10
  • 155
  • 350
templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065