Coupon Accepted Successfully!


The main() Function As A Member Function

We know that the function main() is the starting execution point of every C/C++ program. The main() can be used as a member function of the class. But the execution of program will not start from this member function. The compiler treats member function main() and the user-defined main() differently. No ambiguity is observed while calling function. The following program narrates this concept.

8.36 Write a program to make main() as a member function.

Explanation: In the above program, class A is declared and has one member function main(). In the non-member function main(), the object a invokes the member function main() and a message is displayed as shown in the output.

Test Your Skills Now!
Take a Quiz now
Reviewer Name