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?
if I include class definition file classA.h in classB.h and classC.h, then if classD.h
Share
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. WhenclassD.hincludesclassB.h, it will includeclassA.h. When it then tries to includeclassC.handclassC.htries to includeclassA.h, then nothing happens. This is fine, though, becauseclassC.hcan seeclassA.hbecause it was already included.