I assume you have a class named Point which has member variables named x and y.
Your attempt at the code looks almost right, it just does something extra which isn't needed. Since
read()
is a member function of the class, there's no need here to declare a separate
Point
variable.
Something like this:
1 2 3 4 5 6 7 8 9 10 11
|
void Point::read(istream& ins) {
/**
* Requires: ins is in good state.
* Modifies: ins, x, y.
* Effects: Reads point in form (x,y).
*/
char c;
ins >> c >> x >> c >> y >> c;
}
| |
The return statement is optional, it isn't needed here.
Note in the provided code (the part which you are not supposed to modify), the functions for the operators
<<
and
>>
are not member functions. They are stand-alone functions. As such, they use a Point parameter passed by reference.
In those provided functions, the return
is needed, because the modified stream variable is to be returned. It enables chaining of input or output operations in statements such as
cout << "a = " << a << " b = " << b << '\n';