With respect to the following code segment:
struct Pair{
string name;
double val;
}
vector<Pair> pairs;
double& value(const string& s)
{
for (int i=0; i<pairs.size(); i++)
if (s==pairs[i].name) return pairs[i].val;
Pair p = {s,0};
pairs.push_back(p);
return pairs[pairs.size()-1].val;
}
The author states
For a given argument string, value() finds the corresponding floating-point object (not the value of the corresponding floating-point object); it then returns a reference to it.
What’s the differce between “floating-point object” and its value?
The object is the actual memory block that contains the value.
So if you get the reference you could replace its value, which is still stored in the original vector.
And of course if you’d just get the value (by changing the return value to double without the &) you wouldn’t be able to change the actual value in the vector.