0

why do we define the header files in many programming languages ?

why do we use header files ?

16th Mar 2020, 6:03 PM
Mitraj Gohil
Mitraj Gohil - avatar
3 ответов
0
Hey Mitraj Gohil do use the search bar before asking question
16th Mar 2020, 7:26 PM
✳AsterisK✳
✳AsterisK✳ - avatar
0
Mitraj Gohil I think that what he is asking for is why is the: #ifndef MYCLASS_H #define MYCLASS_H ... #endif if that's the case the reason why we do that is so that your code is not being repeated in case of multiple includes e.x: consider a .h file: file0.h In file1.h: #include"file0.h" ... In file2.h: #include"file0.h" #include"file1.h" ... You see that what happens here is that the contents of file0.h are being copyied twice to file2.h. That's bad cause there might be errors of redefinition, redeclaration. By defining FILE0_H the contents of file0 are only being copyed the first time since the second time, #ifndef FILE0_H prevents it. Another way to do the same thing is by typing #pragma once on top of the header file
16th Mar 2020, 7:52 PM
xaralampis_
xaralampis_ - avatar