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
Evaluate as true or false: !(1 &&0 || !1) a) True b) False c) Invalid statement
What is the use of :: operator in c++?
Can we use this pointer in a class specific, operator-overloading function for new operator?
What is a multimap c++?
What is a dynamic binding in c++?
How to declare an array of pointers to integer?
What will happen if a pointer is deleted twice?
What is the header file for setw?
What are arrays c++?
Name the operators that cannot be overloaded in C++?
If there are two catch statements, one for base and one for derived, which should come first?
What is a tuple c++?
What is struct c++?
What is the type of 'this' pointer? When does it get created?
How do I start a c++ project?