Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What is conversion constructor?

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


Please Help Members By Posting Answers For Below Questions

How a new operator differs from the operator new?

1182


Explain how we implement exception handling in c++?

1106


What is a .lib file in c++?

1046


What are the various situations where a copy constructor is invoked?

1177


What operators can you overload in c++?

1081


Explain the use of virtual destructor?

1121


Does c++ support exception handling?

1111


what is a class? Explain with an example.

1191


What is the difference between set and map in c++?

1178


How can you link a c++ program to c functions?

1141


Is it possible to use a new for the reallocation of pointers ?

1123


What is meant by forward referencing and when should it be used?

1071


What is the use of 'using' declaration in c++?

1192


What is the use of register keyword with the variables?

976


What is class syntax c++?

1205