Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How implementarion code exist just including header file

It's a theorical doubt. Suppouse you have a little library with just two files: lib.h. the headers from lib.cpp, the implementation code. By convention, in C++ we include the lib.h in lib.cpp, that is, the lib.h "doesn't know" about the "lib.cpp" existence. So, to use our library in a program, suppouse: myprogram.cpp and myprogram.h, I have to include just the "lib.h" So, how my program will load the implementation of headers? If the headers files "doesn't know" about the implementations files existence?

like image 552
jhonatanoliveira Avatar asked Sep 22 '26 11:09

jhonatanoliveira


1 Answers

Typically you compile the implementation into a library and link your program to that library. So, unless the implementation code is actually in the header, or in a file included by the header and therefore also distributed, your assertion that "implementation code exist just including header file" is false.

like image 119
juanchopanza Avatar answered Sep 25 '26 01:09

juanchopanza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!