Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will there be a class redefinition if a class is included via two include files indirectly?

Tags:

c++

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?

like image 637
Rn2dy Avatar asked Feb 07 '11 01:02

Rn2dy


1 Answers

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.

like image 51
templatetypedef Avatar answered Oct 13 '22 10:10

templatetypedef