About Header .h | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula gr√°tis
+ 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.

13th Jul 2020, 11:32 AM
Alain Mazy
Alain Mazy - avatar
3 Respostas
+ 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.
13th Jul 2020, 11:40 AM
šĹ†Áü•ťĀŹŚČáԾƜąĎšĻüśėĮ
šĹ†Áü•ťĀŹŚČáԾƜąĎšĻüśėĮ - avatar
+ 1
2. Headers are important if you want to be more specific and clear in your css code
13th Jul 2020, 11:34 AM
Lexi Rockelle Smith
Lexi Rockelle Smith - avatar
+ 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.
18th Jul 2020, 1:33 PM
Alain Mazy
Alain Mazy - avatar