Ask Question
7 August, 17:10

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 non member 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

+5
Answers (1)
  1. 7 August, 18:31
    0
    The operator << is a binary operator so that means that it takes 2 and only 2 parameters.

    ostream &operator << (ostream &strm) const

    {

    return strm << "a" << (obj. width*obj. height) << "window" << endl;

    }

    We could do this but it would not work that way we expect it since with that function, the Windows goes on the left side and the ostream goes on the right side. Therefore, we should call it like this:

    my_window << cout;

    Instead of this:

    cout << my_window;

    Making it a free function, not as a member of the class is the only way to solve this. We may give it public access to that data or we may need to make it a friend it if accesses sensitive data.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Assume the existence of a window class with integer data members width and height. overload the >> operator for the window class - - i. e., ...” in 📙 Mathematics if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers