Research and respond to the following questions: 1. What is a friend function? 2
ID: 3683665 • Letter: R
Question
Research and respond to the following questions:
1. What is a friend function?
2. What is the difference between a friend function of a class and a member function of a class?
3. Suppose that the operator << is to be overloaded for a user-defined class mystery. Why must << overloaded as a friend function?
4. Suppose that the binary operator + is overloaded as a member function for a class strange. How many parameters does the function operator+ have?
5. When should a class overload the assignment operator and defined the copy constructor?
6. What is returned by the function that overloads the operator >> For a class?
7. What is returned by the function that overloads the operator << for a class?
8. What is the purpose of a dummy parameter in a function that overloads the post-increment or Post decrement operator for a class?
9. What type of value should be returned by a function that overloads a rigid relational operator?
10. How many parameters are required to overload the pre-increment operator for a class as a member function?
Assignment Requirements:
After completing your research for each question, use a Word document that includes each question number along with its response. Use a Word table with two columns, question # and your response (see table below).
Question # Researched ResponseExplanation / Answer
2 ) Member Function :
A member function is the one which is defined inside a class and is a member of the class. It may either be a public private or protected function.A Member can access all the variables and other members of the class directly and it have all the access to the members of the class directly .
Friend Function :
On other hand we use friend function in the case when we want to one class to communicate with other class. for this we need to declare that friend function in both the classes and define that friend function outside the associated classes. The friend function is always capable to access all the members of the associated classes. We explicitly use ‘friend’ keyword to define a friend function.A friend function is not a member of a class. But it can access the private data members of the class like a member function of the class.
It is possible to declare a function as friend in any number of classes.
3) << is a stream operator.When you use these as stream operators (rather than binary shift) the first parameter is a stream. Since you do not have access to the stream object (its not yours to modify) these can not be member operators they have to be external to the class. Thus they must either be friends of the class or have access
to a public method that will do the streaming for you.
4) only one parameter has to be passed
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.