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 malloc in c++?
What are pointers used for c++?
What is #include ctype h in c++?
What is a memory leak c++?
What is std namespace in c++?
What is the difference between global int and static int declaration?
How do you declare a set in c++?
How const int *ourpointer differs from int const *ourpointer?
What is private public protected in c++?
What is stl containers in c++?
Tell me an example where stacks are useful?
Define Virtual function in C++.
Explain the static storage classes in c++.
What is the c++ programming language used for?
What is a local variable?