Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How to overload main function in java and c++?

0
Posted

How to overload main function in java and c++?

0

I’m a little confused as to what you want. Function overloading allows you to choose a different implementation based on the function signature (see link below in sources), and is used in both C++ and Java. However the main function in Java and C++ has a fixed signature, so that the compiler will recognize it. In Java: public static void main(String[] args) In C++ (depending on implementation): int main(int argc, const char* argv[], const char* envp) Typically in C++ you drop the third argument envp, as it isn’t really necessary (it contains the current environment variable bindings). So, since the signature is fixed, you can’t really overload these methods. HOWEVER, you can get much the same effect in Java by having more than one main method in your code. For example, you can have two or three classes with main methods. You can then specify which one you want. This won’t work with an executable jar, however, since you have to specify in the manifest which class contains the main to ru

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.