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

Should accessors return values or constant references?

$
0
0

Suppose I have a class Foo with a std::string member str. What should get_str return?

std::string Foo::get_str() const{    return str;}

or

const std::string& Foo::get_str() const{    return str;}

What is more idiomatic in C++?


Viewing all articles
Browse latest Browse all 209

Trending Articles



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