How to implement this?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sci

    How to implement this?

    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(){...}
    };


  • WW

    #2
    Re: How to implement this?

    sci wrote:[color=blue]
    > 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()?[/color]

    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::Cre ate();
    return pAppObject->main(argc, argv);
    }

    --
    WW aka Attila


    Comment

    • Victor Bazarov

      #3
      Re: How to implement this?

      "sci" <sci998@yahoo.c om> wrote...[color=blue]
      > How to encapsulate a main() into a class as a member function? Just like[/color]
      in[color=blue]
      > Java which hides main() function, or like MFC which hides WinMain()?[/color]

      Well, MFC usually comes with its source code. "Use the Source, Luke!"
      [color=blue]
      > Something like:
      >
      > StartClass
      > {
      > public:
      > static int main(){...}
      > };[/color]

      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
      "encapsulat ion" 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.publi c.vc.mfc.

      Victor



      Comment

      • Mohamed Ghouse

        #4
        Re: How to implement this?

        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" <wolof@freemail .hu> wrote in message
        news:blm36f$l7i $1@phys-news1.kolumbus. fi...[color=blue]
        > sci wrote:[color=green]
        > > 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()?[/color]
        >
        > 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::Cre ate();
        > return pAppObject->main(argc, argv);
        > }
        >
        > --
        > WW aka Attila
        >
        >[/color]


        Comment

        • WW

          #5
          Re: How to implement this?

          Mohamed Ghouse wrote:[color=blue]
          > 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.[/color]

          Please read this before you post again:



          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.

          --
          WW aka Attila


          Comment

          Working...