Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 9th, 2005, 4:47 PM   #1
aznluvsmc
Hobbyist Programmer
 
Join Date: Aug 2005
Posts: 137
Rep Power: 4 aznluvsmc is on a distinguished road
Implicit class converions

Hi,

My teacher recently showed the class an example where an a simple addition operator was overloaded for a class. He then went on to show a line where the integer 1 was added to the object. He said the 1 was implicitly converted to an object of the class because a constructor was defined for the class that takes one int as an argument. My question is what rules govern implicit typecasts to user defined classes.
aznluvsmc is offline   Reply With Quote
Old Oct 10th, 2005, 5:04 AM   #2
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Quote:
My question is what rules govern implicit typecasts to user defined classes.
The constructor is used to build the object in such cases. The constructor must take a single argument. Also, You can avoid implicit conversions by using the Explicit keyword with the constructor.
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

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

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:25 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC