According to the standard, you're not writing a true main
function.
Section 3.6.1, paragraph 3: "The function main
shall not be used (3.2) within a program. The linkage (3.5) of main
is implementation-defined. A program that declares main
to be inline
or static
is ill-formed. The name main
is not otherwise reserved. [Example: member function, classes, and enumerations can be called main
, as can entities in other namespaces.]"
This means that, by declaring a member function main
, you're just declaring a member function. It has no special significance, and doesn't mean anything in the class can be called independently. The program would mean entirely the same thing if you substituted snicklefrazz
for that function name and all references.
Stylistically, snicklefrazz
would be better, since it wouldn't lead to any possible conclusion with the standard main
function.
Section 3.6.1, paragraph 1: "A program shall contain a global function called main
, which is the designated start of the program. It is implementation-defined whether a program in a freestanding environment is required to define a main
function."
This means that, unless you're writing in what the standard calls a freestanding environment (typically used in writing embedded systems), you need to define a main
global function, and this is where the program starts.
In Java, a class can have a main
method, which is where the program begins when the class is invoked. This is not the case in C++, and there is no way to accomplish this directly.
(And, as others have mentioned, a class
cannot be static
, and a class definition ends with a semicolon.)