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
What is the importance of mutable keyword?
Explain rtti.
What's c++ used for?
What is the difference between set and map in c++?
What is difference between c++ and c ++ 14?
What apps are written in c++?
Is there finally in c++?
Explain operator overloading.
What are keywords in c++?
Write some differences between an external iterator and an internal iterator? Describe the advantage of an external iterator.
What is singleton class in c++?
Which programming language should I learn first?
Inline parameters : What does the compiler do with the parameters of inline function, that can be evaluated in runtime ?
Explain one-definition rule (odr).
How do you clear a buffer in c++?