I'm still learning C ++, trying to figure out how this works, and came across something that puzzles me.
I have a class that just contains list<string>and has several member functions
class String_list {
public:
String_list(istream&);
list<string> listing;
};
and I wrote my constructor to use a non-member function
String_list::String_list(istream& in) { get_strings(in, listing); }
with
istream& get_strings(istream& in, list<string> lstring)
{
if(in) {
lstring.clear();
string word;
while (in >> word)
lstring.push_back(word);
in.clear();
}
return in;
}
The problem is that the function get_stringseems to work, it does not change the element variable listingthat I passed to it.
, get_strings - (istream& in), lstring listing, , - , , , -, , .
, , .size().