Register on the forum now to remove ALL ads + popups + get access to tons of hidden content for members only!

Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 04-20-2016, 02:59 AM   #1
chinmay.sahoo
Registered User
 
Join Date: Dec 2013
Location: Banglore
Posts: 336
Send a message via AIM to chinmay.sahoo Send a message via MSN to chinmay.sahoo
Thumbs up How do I carry out conversion of one object of user-defined type to another?

To perform conversion from one user-defined type to another we need to provide conversion function. Followingprogram demonstrates how to provide such conversion function.

Quote:
class circle
{
private :
int radius ;
public:
circle ( int r = 0 )
{
radius = r ;
}
} ;
class rectangle
{
private :
int length, breadth ;
public :
rectangle( int l, int b )
{
length = l ;
breadth = b ;
}
operator circle( )
{
return circle ( length ) ;
}
} ;
void main( )
{
rectangle r ( 20, 10 ) ;
circle c;
c = r ;
}
Here, when the statement c = r ; is executed the compiler searches for an overloaded assignment operator in the class circle which accepts the object of type rectangle. Since there is no such overloaded assignment operator, the
conversion operator function that converts the rectangle object to the circle
object is searched in the rectangle class. We have provided such a conversion
function in the rectangle class. This conversion operator function returns a
circle object. By default conversion operators have the name and return type
same as the object type to which it converts to. Here the type of the object is circle and hence the name of the operator function as well as the return type is circle.






Growth on Height | No Addiction Powder | Step Up Height Increaser | Growth on Height
chinmay.sahoo is offline   Reply With Quote

Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Is String a data type in java? Kunal Java 2 04-02-2016 02:39 AM
Increase Ecommerce Conversion martin_stea General Discussion 0 04-03-2015 03:15 AM
The user experience forgingmachine Making money on the web 2 04-20-2014 10:39 PM
Choose the right type of belt on belt hangers peter men Post your ad here 0 10-14-2013 07:53 PM
>>>[UK] Reseller Hosting | Unlimited Domains | Free End User Support<<< RachaelJetkins Post your ad here 0 05-30-2012 03:27 AM


All times are GMT -7. The time now is 07:44 AM.


Powered by vBulletin Copyright © 2013 vBulletin Solutions, Inc.