Why doesn\'t this compile? The linker can\'t find main, but why is this the case?
namespace somenamespace{
int main(void){
return 0;
}
}
The linker is looking for ::main
, not ::somenamespace::main
. The main
that is called at program startup must be in the global namespace.
@Chubsdad has pointed you at the relevant language in the standard that states this. But the standard is now written in a bizarre 'standardese' that bears a lot of resemblance to legalese. I felt a plain english statement of what was going on might be better.
Note: There is a reason the standard is written this way. In the standard you want every term you use to have a very precise and well-defined meaning, and you do not want that meaning to vary depending on context because it makes the standard much harder to interpret. This is actually very similar to the reason that legalese looks the way it does.