|
-
April 29th, 2011, 04:37 PM
#1
about return value
For C++ programmers, if a function needs to return a value to indicate MULTIPLE status, such like success and different situations of failure(more than one, so can't return bool), what value should be returned to indicate success in "c++ standard"? Is there such standard?
-
April 29th, 2011, 04:43 PM
#2
Re: about return value
Why is that sort of return supposed to be "standard" ?
Return is return.
"Switch" to select cases for return code that might be predefined as const and documented for references
-
April 29th, 2011, 04:53 PM
#3
Re: about return value
 Originally Posted by talentspsp
For C++ programmers, if a function needs to return a value to indicate MULTIPLE status, such like success and different situations of failure(more than one, so can't return bool), what value should be returned to indicate success in "c++ standard"? Is there such standard?
You can use an enum, but you'll have to be careful to prevent name clashes, since the values defined in an enum are identifiers in the same scope as the enum. To prevent this, you could use http://www.boost.org/doc/libs/1_46_1..._emulation.hpp.
Code:
enum ReturnValue {
Success,
Failure1,
Failure2
};
ReturnValue foo();
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
April 29th, 2011, 04:55 PM
#4
Re: about return value
 Originally Posted by HarryCummings
Why is that sort of return supposed to be "standard" ?
Return is return.
"Switch" to select cases for return code that might be predefined as const and documented for references
Thanks for your response. Because in C convention, people tend to return 0 for success, but in C++ some functions will return false for fail, so I am not sure what should I return for success and let it make sense for most people now.
-
April 29th, 2011, 05:00 PM
#5
Re: about return value
Return whatever you like; just make sure it's well-documented.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|