O'Reilly logo

Programming in C++, 2nd Edition by Ashok Kamthane

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required