Since C+++ allows function overloading, can we overload main()
?
For example,
int main(const std::string &)
{
return 0;
}
int main(int argc, char *argv[])
{
return main("calling overloaded main");
}
gcc-4.3.4
doesn't compile this, and gives these errors: (see at ideone)
prog.cpp:4: error: first argument of ‘int main(const std::string&)’ should be ‘int’
prog.cpp:4: error: ‘int main(const std::string&)’ takes only zero or two arguments
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:8: error: declaration of C function ‘int main(int, char**)’ conflicts with
prog.cpp:4: error: previous declaration ‘int main(const std::string&)’ here
prog.cpp: In function ‘int main(int, char**)’:
prog.cpp:10: error: invalid conversion from ‘const char*’ to ‘int’
prog.cpp:8: error: too few arguments to function ‘int main(int, char**)’
prog.cpp:10: error: at this point in file
So I'm wondering if the C++ Standard explicitly forbids overloading of main
? If so, which statement?