CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Posts
    9

    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?

  2. #2
    Join Date
    Apr 2011
    Posts
    18

    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

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: about return value

    Quote Originally Posted by talentspsp View Post
    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

  4. #4
    Join Date
    Apr 2011
    Posts
    9

    Re: about return value

    Quote Originally Posted by HarryCummings View Post
    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.

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    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
  •  





Click Here to Expand Forum to Full Width

Featured