0

How linking happens for header file funxtion body

Hi I have understanding that .cpp file is compiled and it generates .obj file which is referred by linker to link function definition for each function call. Header file is just use to find function declaration. Now query is about function definition in header file itself... As it is not used by linker, how it work or function dedinition in header is not a way to achieve. My code base has a common header and few functions of this header is defined in one project and few are in other project... Now one more small function I am trying to add into header but it has to be inline and not related to either of these tqo existing projects Can i directly define in header and use this header as include in my peoject ? Dont i have to link this ? Only header include will be sufficient ?

5th Aug 2022, 6:05 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Respuestas
+ 1
Hi Ketan Lalcheta, yes it will be an inline function in the header file and can include anywhere, only the header will be enough because it will work as inline, A header file contains: 1- Function definitions(inline) 2- Data type definitions 3- Macros The “#include” preprocessor is responsible for directing the compiler that the header file needs to be processed before compilation and includes all the necessary data type and function definitions. Note: We can’t include the same header file twice in any program.
11th Aug 2022, 7:09 AM
Ubaidullah
Ubaidullah - avatar
0
Thanks
11th Aug 2022, 7:19 AM
Ketan Lalcheta
Ketan Lalcheta - avatar