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

Does it make sense to return fundamental types by const value?

$
0
0

Which is better:

bool MyClass::someQuery() const;const bool MyClass::someQuery() const;

I've been using const bool since I'm sure I remember hearing it's "what the ints do" (for e.g. comparison operators) but I can't find evidence of that anywhere, mostly due to it being difficult to Google and IntelliSense not helping out any ;) Can anyone confirm that?

To me returning const values (this isn't just about bool) makes more sense; it'll prevent temporaries being modified, which is almost always going to be a programmer mistake. I just want something to back that up so I can extol returning const values to my colleagues :)


Viewing all articles
Browse latest Browse all 207

Trending Articles



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