I am developing a library of some utility functions in C++. I have a doubt regarding the function signatures in that library. If a function takes some parameters and returns a value, should the variable into which the result of that function is stored also be passed as a parameter to that function? How should I handle the error conditions and return values for errors?
Share
For C++ you should return the result and handle errors with exceptions.
But the result then is copied from the function to the calling context. With primitive datatypes this is the fastest possible way. But when you have complex datastructures, it can be faster to pass a reference to a result parameter – although it’s not as clean code as the solution above, An example would be: