How to implement this?

S

sci

How to encapsulate a main() into a class as a member function? Just like in
Java which hides main() function, or like MFC which hides WinMain()?

Something like:

StartClass
{
public:
static int main(){...}
};
 
W

WW

sci said:
How to encapsulate a main() into a class as a member function? Just
like in Java which hides main() function, or like MFC which hides
WinMain()?

You cannot. So you have to go through the ordeal of writing:

int main() {
return someclass::main();
}

or the worse:

int main( int argc, char *argv[]) {
AppClass appObject;
return appObject.main(argc, argv);
}

or the unbearable one (which you will never need to touch again):

#include "someframework.hpp"

int main( int argc, char *argv[]) {
AppClass *pAppObject = AppFactory::Create();
return pAppObject->main(argc, argv);
}
 
V

Victor Bazarov

sci said:
How to encapsulate a main() into a class as a member function? Just like in
Java which hides main() function, or like MFC which hides WinMain()?

Well, MFC usually comes with its source code. "Use the Source, Luke!"
Something like:

StartClass
{
public:
static int main(){...}
};

I am not sure what you need it for. If you want to create some kind
of "light-weight" MFC clone, look at how MFC is made, and follow suit.

Note that when using MFC, there should be no 'main' function in your
program. The 'main' will be supplied from the library. There is no
"encapsulation" per se. The trick is that the library-supplied 'main'
finds out what the current "CWinApp" object is and calls its members
in a certain order with certain arguments.

More on MFC in microsoft.public.vc.mfc.

Victor
 
M

Mohamed Ghouse

You cannot encapsulate main into a class as a member function.
This is one of the reasons C++ is not termed as a __pure__ OO Programing
Language.

afaik,
MFC does not encapsulate main into a class as a member function. Instead
main() is added by the library.

WW said:
sci said:
How to encapsulate a main() into a class as a member function? Just
like in Java which hides main() function, or like MFC which hides
WinMain()?

You cannot. So you have to go through the ordeal of writing:

int main() {
return someclass::main();
}

or the worse:

int main( int argc, char *argv[]) {
AppClass appObject;
return appObject.main(argc, argv);
}

or the unbearable one (which you will never need to touch again):

#include "someframework.hpp"

int main( int argc, char *argv[]) {
AppClass *pAppObject = AppFactory::Create();
return pAppObject->main(argc, argv);
}
 
W

WW

Mohamed said:
You cannot encapsulate main into a class as a member function.
This is one of the reasons C++ is not termed as a __pure__ OO
Programing Language.

afaik,
MFC does not encapsulate main into a class as a member function.
Instead main() is added by the library.

Please read this before you post again:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.4

And please reply to the post you are answering to. You have answered to the
OP replying to my post, with which you have implied that I stated that main
can be a member function etc. Furthermore the OP might not even read your
post, since you have replied to mine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,143
Messages
2,570,822
Members
47,368
Latest member
michaelsmithh

Latest Threads

Top