On a whim, I tried to define the main function as a template function using clang 2.9:
template <typename T = void>
int main(int argc, char **argv)
{
}
and received the following error.
error: 'main' cannot be a template
int main(int argc, char **argv)
^
Does anyone know what section of the standard forbids this, and what the relevant text is?
Well, how about this (3.6.1):
A program shall contain a global function called main, which is the designated start of the program. [...] This function shall not be overloaded. It shall have a return type of type int, but otherwise its type is implementation-defined.
Since templates are not functions, I don't think you have any choice in the matter. In particular, the function has to be main
, not main<>
as in your example; and your main
isn't a function, but a template, precluding the existence of another function called main
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With