"how to return multiple error codes from c++ function" Code Answer

37

You can either return an object that has multiple error fields or you can use 'out'parameters.

How you do this depends on your design and what exactly you are trying to return back. A common scenario is when you need to report back a status code along with a message of sorts. This is sometimes done where the function returns the status code as the return value and then returns the message status via an 'out' parameter.

If you are simply returning a set of 'codes', it might make more sense to construct a struct type and return that. In that case, I would be prone to pass it in as an out parameter and have the method internally update it instead of allocating a new one each time.

Are you planning on doing this once or many times?

By Michael Simbirsky on February 14 2022

Answers related to “how to return multiple error codes from c++ function”

Only authorized users can answer the Search term. Please sign in first, or register a free account.