separating the interface from the implementation.
The header declares "what" a class (or whatever is being implemented) will do
The cpp file defines "how" it will perform those features.
class reusability
other cpp file that wanna use our class, only need the interface(hpp file).
if hpp file have implementation code. it will be included in other cpp file.
refereces
I've never really understood why C++ needs a separate header file with the same functions as in the .cpp file. It makes creating classes and refactoring them very difficult, and it adds unnecessary files to the project. And then there is the problem with having to include header files, but…
Why does C++ have header files and .cpp files?
I would like to ask you about your opinion about header only style of c++ programming.
I’m stick with header only approach for the next reasons:
- Not repeating of functions signatures.
- Define class method outside of class is a boilerplate (thinking of template methods of template class)
- There are lot of templated c++ code that anyway needs to be placed…
Top comments (0)