It is true that C++ requires main
to be the "entrypoint" of the program, at least under what's called "hosted implementations" (the ones you're probably using). This is why you get a linker error with GCC if you forgot to define a main
.
However, in practice, the gap where your program ends and the "runtime" begins, makes things seem a little more wooly — when your program is launched, the first functions called are actually inside the runtime, which will eventually get around to invoking main
. It is actually this invocation which causes the linker error if you forgot to define a main
.
Microsoft has decided that, for Windows GUI programs, instead of invoking main
, their runtime will invoke WinMain
. As a consequence, you have to define a function WinMain
for it to find, instead of main
. Technically this violates the C++ standard, but it works because Microsoft makes it work.