The usual way is to put the implementation of functions in a separate cpp file, which is not included in other files, just compiled. Thus, it is easier to manage dependencies.
If the implementation of the function is indicated in the class definition (as in your second example), this is a hint for the compiler to embed this function (which it may or may not do at the end, depending, for example, on the inside of the function). Generally, functional bodies that are longer than a few lines of code are better placed in the cpp file, since they are probably not going to be embedded, however they may include additional dependencies and clutter the class definition.
The exception is the template functions, in which the bodies must also be in the header, since the compiler must see them in order to create an instance of the template.
source share