BEGINNERS: Combining two codes - doesn't work !

This is why God gave us object orientated programming.

Learn how to use h files to define classes and reusable code and your life will be way easier.

Whether you put your declarations in an h file and your definitions in a cpp file are up to you.

Personally, it depends on the complexity.

If I want a quick way to see the various methods and variable names and don't care about the implementation, then I use the h + cpp file way. For example, my i2c display class uses an h file and a cpp file so I don't have to dig through hundreds of lines of code to find method names. They're all neatly listed in the h file.

If it's just a simple self contained class then I just use an h file. For example, the map class for my platformer is just a single h file since it has only a couple functions. I don't really need to break the method implementations out into a separate cpp file at this point.