Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1) Explain what an “inline” function is, why it is used, and its advantages over

ID: 3855063 • Letter: 1

Question

1) Explain what an “inline” function is, why it is used, and its advantages over the standard C macro created with a #define. 2) Explain what a “friend” function is and how it is used. 3) Given that a class will have a pointer to memory that is allocated at run time, what member methods and/or operators will be needed to be written (as a minimum) and why? 4) How does a programmer create a function in C++ that will have default values for parameters? 5) Explain the uses of the “public” and “private” keywords in class definitions (i.e. what do each of the sections mean). 6) Explain how to create and use a “template” class. 7) Explain function overloading. 8) Explain the limitations of operator overloading. 9) Explain the use of the keyword “explicit” in C++.

Explanation / Answer

1)Answer:

inline” function:

Inline functions are those functions whose definition is small and can be substituted at the place where its function call is made. ... Compiler interprets the inline keyword as a mere hint or request to substitute the code of function into itsfunction call.

use:

compiler substitute the body of the function inline by performing inline expansion, i.e. by inserting the function code at the address of each function call, thereby saving the overhead of a function call.

Inline functions provides following advantages over macros:

2)Answer:

“friend” function:

A friend function of a class is defined outside that class' scope but it has the right to access all private and protected members of the class. Even though the prototypes for friend functions appear in the class definition, friends are not member functions.

->

A friend can be a function, function template, or member function, or a class or class template, in which case the entire class and all of its members are friends.

To declare a function as a friend of a class, precede the function prototype in the class definition with keyword friend as follows:

To declare all member functions of class ClassTwo as friends of class ClassOne, place a following declaration in the definition of class ClassOne:

Consider the following program:

When the above code is compiled and executed, it produces the following result: