Saturday, 15 March 2014

c++ - What does the "&" symbol mean in the return type of a function? -



c++ - What does the "&" symbol mean in the return type of a function? -

i'm reading c++ book explains next function:

istream& read_hw(istream& in, vector<double>& hw) { if (in) { hw.clear() ; double x; while (in >> x) hw.push_back(x); in.clear(); } homecoming in; }

the book explained "&" in arguments list mean passed reference, there no explanation symbol in istream&: in homecoming type of function. removing causes many compilation errors. can clarify?

the function returns reference well. in case, object pass in returned function, can "chain" calls function:

in.read_hw(hw1).read_hw(hw2);

this mutual pattern in c++, when in iostreams library.

c++ function return-type

No comments:

Post a Comment