Answer Posted / sachin mahajan
This is related to typecasting of user defined datatypes ie
Convertion of one class object to other class object.
Ex
I want to type cast REAL class object to COMPLEX Class object
Both REAL class and COMPLEX Class are user defined.
COMPLEX objComplex(6,3); //6 is real and 3 is imagnary
REAL objReal(5);
objComplex=objReal;
//end result of the above statement should be that
objComplex //should have 5 as real part and 0 as imaginary
//There are two solutions to it
//a)write conversion constuctor
//b)Overload assignment operator
// (a) for this add this in the COMPLEX Class
COMPLEX :: COMPLEX(REAL r)
{
real=r.value; // value is the only data member of REAL class
imag=0;
}
| Is This Answer Correct ? | 14 Yes | 2 No |
Post New Answer View All Answers
Is python written in c or c++?
What is do..while loops structure?
State the difference between delete and delete[].
Is c# written in c++?
What is setw manipulator in c++?
Which function should be used to free the memory allocated by calloc()?
Why isn't sizeof for a struct equal to the sum of sizeof of each member?
What are destructors?
Describe private, protected and public?
Comment on assignment operator in c++.
Is c++ the hardest programming language?
Why is c++ not purely object oriented?
Explain the benefits of proper inheritance.
Explain data encapsulation?
What is the difference between #define debug 0 and #undef debug?