Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 230

Is there a "return NULL" equivalent for return-by-reference functions?

$
0
0

I'm working with existing code that returns a reference, something like this:

int &func(){   static int i = 5;   return i;}

I would like to return an error case as "NULL" but of course NULL doesn't work in a return-by-reference function. If this were returning a pointer I might do this:

int *func(){   static int i = 5;   if (!good)       return NULL;   else       return &i;}

Besides converting to a pointer-based return value, is there a best practice for returning a failure state?


Viewing all articles
Browse latest Browse all 230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>