Assume the existence of a Window class with integer data members width and height. Overload the >> operator for the Window class — i.e., write a nonmember istream-returning function that accepts a reference to an istream object and a reference to a Window object and reads the next two values from the istream in to the width and height members respectively. Don’t forget to have the function return the proper value as well. Assume the operator has been declared a friend in the Window class .

LANGUAGE: C++

CHALLENGE:

Assume the existence of a Window class with integer data members width and height. Overload the >> operator for the Window class — i.e., write a nonmember istream-returning function that accepts a reference to an istream object and a reference to a Window object and reads the next two values from the istream in to the width and height members respectively. Don’t forget to have the function return the proper value as well. Assume the operator has been declared a friend in the Window class.

SOLUTION:


friend istream& operator >>(istream& ins, Window& obj){
    int w, h;
    ins >>w;
    ins >>h;
    obj.height=h;
    obj.width=w;
    return ins;
}