The tutorial I am following has defined a class,
then underneath the class (in the same header file)
he has defined some (constant) variables, overloaded some operators
and defined a simple function.
My question is, why is this not done in the .cpp file?
What is the difference? Thanks
Can I also check, if I understand correctly: It is fine to declare constant
variables like this because they are not global, you can only use them
in the same header right?
If the functions are templates or inline they have to be defined in the header file. If that is not the case I guess the tutorial writer is just being lazy.
You can access constants from other files if they include the header. Global constants are fine. When people talk about globals being bad they often mean non-const globals.