Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need quote from standard about legality of main function as a template function

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?

like image 494
Michael Price Avatar asked Nov 16 '11 04:11

Michael Price


1 Answers

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.

like image 104
Kerrek SB Avatar answered Oct 07 '22 14:10

Kerrek SB