About Header .h | Sololearn: Learn to code for FREE!

+1

About Header .h

Hello guys, I have 2 questions about header (.h) files. 1. If they contain the declarations, and the .cpp files are their implementation, can we consider these headers files as interfaces whose declarations must absolutely be implemented in the cpp? 2. Are Headers really essential? Other languages besides C don't use this kind of thing.

7/13/2020 11:32:09 AM

Alain Mazy

3 Answers

New Answer

+2

1. Yes. 2. Headers are essential because they make codes more clean and separated clearly. Let's say I have sample.h, sample.cpp, main.cpp. Instead of putting all declarations and definitions in main.cpp and make it 1000 lines or even longer, I can separate it to sample.h and sample.cpp to make it like only 300 lines. This way I can make it more clear and easier to debug.

+1

2. Headers are important if you want to be more specific and clear in your css code

+1

Ok, Thanks guys, I got it right, so far, I only did OOP, and I split my program into a number of small classes where each had its own distinct purpose, that's a bit the same if I understand correctly.