Why does C++ have header files and .cpp files?


C++ has header and .ccp files for separating the interface from the implementation. The header files declare "what" a class (or whatever is being implemented) will do, ie the API of the class, kind of like an interface in Java. The cpp file on the other hand defines "how" it will perform those features, ie, the implementation of these declared functionality.

This reduces dependencies. The code that uses the header doesn't need to know all the details of the implementation and any other classes/headers needed only for that. It just needs to focus on things it is trying to implement. This reduces compile times and the amount of recompilation needed when you change the implementation.


Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements