Right return

A

Alex Tenenboym

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_SUCCESS 2

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

void CAnotherClass::OnProc
{
CSomeClass someclass_object;
switch(someclass_object.MyProc(...))
{
case MY_PROC_ERR:
ShowError();
break;
case MY_PROC_PARTIAL_SUCCESS:
Do AdditionalProcessing(...);
break;
case MY_PROC_FULL_SUCCESS:
Finish();
break;
}
}

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

Thanks

Alex
 
W

WW

Alex said:
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_SUCCESS 2

int const MyProcErr etc. C++ is not C. And the whole thing goes inside
CSomeClass.
int CSomeClass::MyProc(...)
{
//Do processing
return iRet;
}
???

void CAnotherClass::OnProc
{
CSomeClass someclass_object;
switch(someclass_object.MyProc(...))
{
case MY_PROC_ERR:
ShowError();
break;
case MY_PROC_PARTIAL_SUCCESS:
Do AdditionalProcessing(...);
break;
case MY_PROC_FULL_SUCCESS:
Finish();
break;
}
}

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

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

David White

Alex Tenenboym said:
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_SUCCESS 2

I hope these #defines are no longer typical. An enum or const ints would be
better.
int CSomeClass::MyProc(...)
{
//Do processing
return iRet;
}

void CAnotherClass::OnProc
{
CSomeClass someclass_object;
switch(someclass_object.MyProc(...))
{
case MY_PROC_ERR:
ShowError();
break;
case MY_PROC_PARTIAL_SUCCESS:
Do AdditionalProcessing(...);
break;
case MY_PROC_FULL_SUCCESS:
Finish();
break;
}
}

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

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

DW
 
J

jeffc

Alex Tenenboym said:
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_SUCCESS 2

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

void CAnotherClass::OnProc
{
CSomeClass someclass_object;
switch(someclass_object.MyProc(...))
{
case MY_PROC_ERR:
ShowError();
break;
case MY_PROC_PARTIAL_SUCCESS:
Do AdditionalProcessing(...);
break;
case MY_PROC_FULL_SUCCESS:
Finish();
break;
}
}

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

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

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

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top