8.Answer these questions about overloading the stream operators: In a class, why
ID: 3594588 • Letter: 8
Question
8.Answer these questions about overloading the stream operators:
In a class, why do you include the functions that overload the stream insertion, <<, and extraction, >>, operators as friend functions?
What is returned by the function that overloads the >> operator for a class?
What is returned by the function that overloads the << operator for a class?
9. What is the purpose of a dummy parameter in a function that overloads the post-increment or post-decrement operator for a class?
10. What type of value should be returned by a function that overloads a relational operator?
11. How many parameters are required to overload:
the pre-increment operator for a class as a member function?
the pre-increment operator for a class as a friend function?
the post-increment operator for a class as a member function?
the post-increment operator for a class as a friend function?
Explanation / Answer
8.Answer these questions about overloading the stream operators:
In a class, why do you include the functions that overload the stream insertion, <<, and extraction, >>, operators as friend functions?
This is needed because these stream functions are called without creating object of that class and hence if they are not friend function they can't be called without creating object.
What is returned by the function that overloads the >> operator for a class?
It return istream object
What is returned by the function that overloads the << operator for a class?
It return ostream object.
9. What is the purpose of a dummy parameter in a function that overloads the post-increment or post-decrement operator for a class?
dummy int parameter is taken to disambiguate as compiler can differtiate between two function of same name with parameters only
10. What type of value should be returned by a function that overloads a relational operator?
It should return bool value as relational opertor expect bool to be its result
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.