I have a function that computes something and if the result is not valid i want to return something like "NULL". I have found a way using pointers, but is there an easier way to do that?
It really depends on the semantics of your function. If the function's contract is that it will return an int to the user and for some reason it is unable to do so, then your function should be throwing an exception. If the function's contract is that it will either return an int or nothing to the user, then you might want to use boost::optional.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With