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
Which sort does c++ use?
How would you use the functions randomize() and random()?
Write a program which employs Recursion
What are the characteristics of friend functions?
Write a program to add three numbers in C++ utilizing classes.
What is set in c++?
Which bit wise operator is suitable for turning off a particular bit in a number?
What are literals in C++?
Write bites in Turbo c++ Header ("Include") Files.
What does iomanip mean in c++?
What are features of c++?
What is the use of dot in c++?
What are iterators in c++?
Why iomanip is used in c++?
Describe linked list using C++ with an example.