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 prototype of printf function?
Which one is better- macro or function?
What is array in c++ pdf?
What do you mean by late binding?
Which sort does c++ use?
Why do we use structure in c++?
What is dev c++ used for?
Can we run c program in turbo c++?
What is a tuple c++?
Explain virtual class and friend class.
Is it possible to write a c++ template to check for a function's existence?
Is c++ a good first language to learn?
Is c++ primer good for beginners?
What is pointer in c++ with example?
When we use Abstract Class and when we use Interface?where we will implement in real time?