Ask Question
27 September, 01:23

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

+1
Answers (1)
  1. 27 September, 01:47
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers