Class API design: should I return a field in getXxx() method by value or as a const-ref?

In general, I would go with the const& version, since it avoids unnecessary copying.

The general rule is to return by value unless it is part of the contract that you return a reference to something internal (e.g. Like vector::operator). In addition to threading issues, there can easily be lifetime of object issues: if you return a reference, and the client captures it by reference, then deletes your object, he's left with a dangling reference.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions