Why have header files?
-
-
Because C++ has to be linked. Compilation units need to know about the declarations of types in other compilation units. Interpreted languages can wait until the VM is running to test whether all required compilation units are present. C++ needs a way of not ending up with duplicate definitions, in multiple compilation units. Header files generally contain just the declarations.
If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling
-
Actually I hated it when the first time I started to learn Java and C# and found out that they don't have header files, every function body reside in the class definition making the class definition so lengthy and hard to read, sometimes they look like a mess to me. I think I like C++ header files very much.
-
Because C++ has to be linked. Compilation units need to know about the declarations of types in other compilation units. Interpreted languages can wait until the VM is running to test whether all required compilation units are present. C++ needs a way of not ending up with duplicate definitions, in multiple compilation units. Header files generally contain just the declarations.
If you can keep you head when all about you Are losing theirs and blaming it on you; If you can dream - and not make dreams your master; If you can think - and not make thoughts you aim; Yours is the Earth and everything that's in it. Rudyard Kipling