Can main() be overloaded in C++?
Predict the output of following C++ program.
The above program fails in compilation and produces warnings and errors (See this for produced warnings and errors). You may get different errors on different compilers.
To overload main() function in C++, it is necessary to use class and declare the main as member function. Note that main is not reserved word in programming languages like C, C++, Java and C#. For example, we can declare a variable whose name is main, try below example:
The following program shows overloading of main() function in a class.
The outcome of program is:
3 I love C++ 9 6
This article is contributed by Pravasi Meet. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Please Login to comment...