Given the following class declaration and definition, is it indispensable to provide a destructor? class Complex{ public: Complex(double real = 0.0, double imaginary = 0.0); string ToString()const; Complex& operator=(const Complex& rhs); Complex operator+(const Complex& rhs)const; private: double _real; double _imaginary; };

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 26SA
icon
Related questions
Question
Given the following class declaration and definition, is it indispensable to provide a destructor?
class Complex{
public:
Complex(double real = 0.0, double imaginary = 0.0);
string ToString()const;
Complex& operator=(const Complex& rhs);
Complex operator+(const Complex& rhs)const;
%3D
private:
double real;
double _imaginary;
};
Complex: :Complex(double real, double imaginary){
_real = real;
_imaginary = _imaginary;
%3D
}
string Complex::ToString()const{
stringstream ss;
ss < _real « " + " << _imaginary << "i";
return ss.str();
Complex& Complex::operator=(const Complex& rhs){
_real = rhs._real;
Limaginary = rhs._imaginary;
return *this;
Complex Complex::operator+(cinst Complex& rhs)const{
Complex retVal(_real + rhs._real, Limaginary + rhs._imaginary);
return retVal;
}
True
False
Transcribed Image Text:Given the following class declaration and definition, is it indispensable to provide a destructor? class Complex{ public: Complex(double real = 0.0, double imaginary = 0.0); string ToString()const; Complex& operator=(const Complex& rhs); Complex operator+(const Complex& rhs)const; %3D private: double real; double _imaginary; }; Complex: :Complex(double real, double imaginary){ _real = real; _imaginary = _imaginary; %3D } string Complex::ToString()const{ stringstream ss; ss < _real « " + " << _imaginary << "i"; return ss.str(); Complex& Complex::operator=(const Complex& rhs){ _real = rhs._real; Limaginary = rhs._imaginary; return *this; Complex Complex::operator+(cinst Complex& rhs)const{ Complex retVal(_real + rhs._real, Limaginary + rhs._imaginary); return retVal; } True False
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Reference Types in Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning