Quantcast
Viewing latest article 24
Browse Latest Browse All 203

Should accessors return values or constant references?

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 latest article 24
Browse Latest Browse All 203

Trending Articles



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