0

I'm wondering if it is possible to declare main as template function like this:

    template<typename T>
    int main(int argc, char *argv[]) {
        //code here
    }

The compiler says the following

error: cannot declare `::main' to be a template

Is there any reference in the standard?

  • 2
    *Why* would you want to do that?! – Biffen Apr 27 '15 at 07:18
  • For theoretical purposes – define void int Apr 27 '15 at 07:19
  • 2
    [basic.start.main] would be a good read I suppose. Among many other things, it specifies "A program shall contain a global function called `main`, which is the designated start of the program" - I don't see anything in there about allowing a *function template*. And how would you expect the compiler to *instantiate* it? Or were you planning on explicitly instantiating it, questionably violating paragraph(3) of the same section: "The function `main` shall not be used within a program..." etc. – WhozCraig Apr 27 '15 at 07:29

0 Answers0