开发者

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

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开发者_JAVA技巧 class redefinition?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜