now when I look at the code and see that I don't return anything from the function, I don't understand why it worked at all. the compiler should give a serious error, or the program should crash imidiately if it doesn't break the laws of C++.
Yeah, this is something to get to know about C++. There are a few different levels of "serious error" in C++.
First, there are compilation errors, i.e., when the code just doesn't compile, but that is usually restricted to syntax errors (i.e., code that breaks the syntax rules of C++), not so much logical errors or "bugs" (although, there are advanced techniques in C++ to get the compiler to detect logical errors and bugs, but I won't get into that here).
Then, you have run-time errors, but these are also limited by how much error checking you do in your code, because the C++ language tries to be an "opt-in" language in the sense that most run-time checks are things that the programmer can choose to adopt in his code (or by compiler options), but they are generally not there by default, as they hinder performance. And because C++ is native (does not run in an interpreter or virtual machine) there are very little built-in safety checks, only the most critical ones (like memory overflows or access violations), and generally, these just terminate the application with no further information about the errors.
Then, arguably the most important class of "serious errors" is …