0

I'm learning a bit of c++ and came across a project on github that implements the SHA256 hashing algorithm. This project has all its code in a header file. This confuses me a little. According to a c++ website(unofficial), the header file is sort of definition(interface) of which methods are available and the cpp file has the implementation of these methods.

Questions:

  • Is it "correct" to do the implementation inside your header like the github project?
    • If so, when do you put the implementation in the header?
    • If not, does this mean that the sha256 project could be improved by splitting in a header and cpp file?
Gert Kommer
  • 1,163
  • 2
  • 22
  • 49
  • 4
    That is not "the C++ website". And yes, putting all the code in a header is very common. –  Apr 12 '18 at 12:40
  • https://softwareengineering.stackexchange.com/questions/167723/what-should-and-what-shouldnt-be-in-a-header-file – jamek Apr 12 '18 at 12:41
  • 3
    It's using templates: [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – Bo Persson Apr 12 '18 at 12:44
  • "cplusplus.com" sounds official, but in reality it's made by "enthusiasts" and has plenty of miscomprehensions and beginners' guesses. – molbdnilo Apr 12 '18 at 12:52
  • @molbdnilo Noted, changed text to make it clear – Gert Kommer Apr 12 '18 at 13:32

0 Answers0