In: Computer Science
Write the 2 possible ways the compiler could make function calls for the following operation. If there is a reason why there should only be one way to call this function, then explain why. The num variables are instances of the Number class.
fout << num;
____________________________________________________________________________________________________________________________________________________
Write the following function prototypes that would be declared for the Cplx class (you don't need to write the function definitions or write the rest of the class). Cplx class is a complex class with lots of data. Remember to show the return type, and const where needed. For all your parameters, call them lval or rval to show that you understand where they would be in the operation
// << function
// + as a non-member function
// + as a member function
// = as a member function
/*
Write the 2 possible ways the compiler could make function calls
for the following operation.
Answer:
1) Member function
2) Non - member function (friend function )
*/
/*
If there is a reason why there should only be one way to call this
function, then explain why.
Answer:
There is only one way to call the function because of operator
overloading.
The function signature are different to distinguish between
functions,
based on the number of parameter and type of parameter compiler
determines
which function to call.
The key word friend before the function indicates it is a non -
member function.
*/
/*
The num variables are instances of the Number class.
fout << num;
The above statement is used to display the value stored in the data
member
of the class Number.
*/
/*
#include <iostream>
using namespace std;
class Cplx
{
public:
// << function
friend ostream& operator<<(ostream& , Cplx&);
+ as a non-member function
friend Cplx operator +(const Cplx &lval, const Cplx
&rval);
// + as a member function
Cplx operator +(const Cplx &rval);
// = as a member function
void operator = (const Cplx &rval);
};
*/