C++ PROGRAMMING Consider the following declaration: (8, 9) template class strang
ID: 3820862 • Letter: C
Question
C++ PROGRAMMING
Consider the following declaration: (8, 9) template class strange {. .. private: type a; type b;}; Write a statement that declares sObj to be an object of type strange such that the private member variables a and b are of type int. Write a statement that shows the declaration in the class strange to overload the operator == as a member function. Assume that two objects of type strange are equal if their corresponding member variables are equal. Write the definition of the function operator == for the class strange, which is overloaded as a member function.Explanation / Answer
a. The object declaration is as follows,
strange<int> sObj;
b. bool operator==(strange &rhs)const;
c. Definition of == operator
template <class type>
class strange
{
private:
type a, b;
bool operator==(strange &rhs)const
{
if(a==rhs.a && b==rhs.b)
return true;
else return false;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.