8.28  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.

#include<conio.h>

#include<iostream.h>

class A

{

public:

void main()

{

cout<<endl<<“In member function main()”;

}

};

int main()

{

clrscr();

A *a;

a->main();

return 0;

}

OUTPUT

In member function main()

Explanation: In the above program, class A

Get Programming in C++, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.