DEV Community

yeonseong
yeonseong

Posted on

why seperate hpp and cpp

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

195

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…

543

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

Reddit Logo Header only vs hpp/cpp styles

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:

  1. Not repeating of functions signatures.
  2. Define class method outside of class is a boilerplate (thinking of template methods of template class)
  3. There are lot of templated c++ code that anyway needs to be placed…

Top comments (0)