Right return

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

    Right return

    This is a typical way to get a return from a function

    #define MY_PROC_ERR 0
    #define MY_PROC_PARTIAL _SUCCESS 1
    #define MY_PROC_FULL_SU CCESS 2

    int CSomeClass::MyP roc(...)
    {
    //Do processing
    return iRet;
    }

    void CAnotherClass:: OnProc
    {
    CSomeClass someclass_objec t;
    switch(someclas s_object.MyProc (...))
    {
    case MY_PROC_ERR:
    ShowError();
    break;
    case MY_PROC_PARTIAL _SUCCESS:
    Do AdditionalProce ssing(...);
    break;
    case MY_PROC_FULL_SU CCESS:
    Finish();
    break;
    }
    }

    Do you know a better way? Small improvements like using enum are not
    suffice

    Thanks

    Alex
  • WW

    #2
    Re: Right return

    Alex Tenenboym wrote:[color=blue]
    > This is a typical way to get a return from a function
    >
    > #define MY_PROC_ERR 0
    > #define MY_PROC_PARTIAL _SUCCESS 1
    > #define MY_PROC_FULL_SU CCESS 2[/color]

    int const MyProcErr etc. C++ is not C. And the whole thing goes inside
    CSomeClass.
    [color=blue]
    > int CSomeClass::MyP roc(...)
    > {
    > //Do processing
    > return iRet;
    > }[/color]

    ???
    [color=blue]
    > void CAnotherClass:: OnProc
    > {
    > CSomeClass someclass_objec t;
    > switch(someclas s_object.MyProc (...))
    > {
    > case MY_PROC_ERR:
    > ShowError();
    > break;
    > case MY_PROC_PARTIAL _SUCCESS:
    > Do AdditionalProce ssing(...);
    > break;
    > case MY_PROC_FULL_SU CCESS:
    > Finish();
    > break;
    > }
    > }
    >
    > Do you know a better way? Small improvements like using enum are not
    > suffice[/color]

    You need to post code which show what you are trying to do. What is partial
    success? And if it is onyl partially successfull why don't you retry it
    after the additional processing?

    Unless we know what error and partial success means there is no way we can
    give a good advice.

    --
    WW aka Attila


    Comment

    • David White

      #3
      Re: Right return

      Alex Tenenboym <alexten@bigfoo t.com> wrote in message
      news:97c4e780.0 309221630.6d97a c99@posting.goo gle.com...[color=blue]
      > This is a typical way to get a return from a function
      >
      > #define MY_PROC_ERR 0
      > #define MY_PROC_PARTIAL _SUCCESS 1
      > #define MY_PROC_FULL_SU CCESS 2[/color]

      I hope these #defines are no longer typical. An enum or const ints would be
      better.
      [color=blue]
      > int CSomeClass::MyP roc(...)
      > {
      > //Do processing
      > return iRet;
      > }
      >
      > void CAnotherClass:: OnProc
      > {
      > CSomeClass someclass_objec t;
      > switch(someclas s_object.MyProc (...))
      > {
      > case MY_PROC_ERR:
      > ShowError();
      > break;
      > case MY_PROC_PARTIAL _SUCCESS:
      > Do AdditionalProce ssing(...);
      > break;
      > case MY_PROC_FULL_SU CCESS:
      > Finish();
      > break;
      > }
      > }
      >
      > Do you know a better way? Small improvements like using enum are not
      > suffice[/color]

      "Better" how? Assuming you are doing the right thing in each case, this code
      is clear and maintainable. What more do you want?

      DW



      Comment

      • jeffc

        #4
        Re: Right return


        "Alex Tenenboym" <alexten@bigfoo t.com> wrote in message
        news:97c4e780.0 309221630.6d97a c99@posting.goo gle.com...[color=blue]
        > This is a typical way to get a return from a function
        >
        > #define MY_PROC_ERR 0
        > #define MY_PROC_PARTIAL _SUCCESS 1
        > #define MY_PROC_FULL_SU CCESS 2
        >
        > int CSomeClass::MyP roc(...)
        > {
        > //Do processing
        > return iRet;
        > }
        >
        > void CAnotherClass:: OnProc
        > {
        > CSomeClass someclass_objec t;
        > switch(someclas s_object.MyProc (...))
        > {
        > case MY_PROC_ERR:
        > ShowError();
        > break;
        > case MY_PROC_PARTIAL _SUCCESS:
        > Do AdditionalProce ssing(...);
        > break;
        > case MY_PROC_FULL_SU CCESS:
        > Finish();
        > break;
        > }
        > }
        >
        > Do you know a better way? Small improvements like using enum are not
        > suffice[/color]

        Huh? A "better" way to return a value from a function? Your question is
        unclear.


        Comment

        Working...