C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Function overloading, Operator overloading in Ironpython


Posted Date: 28 Jun 2007    Resource Type: Articles    Category: .NET Framework

Posted By: Sunil Pottumuttu       Member Level: Silver
Rating:     Points: 10




FUNCTION OVERLOADING AND OPERATOR OVERLOADING IN IRONPYTHON
But there is a simple way to achive this using argbitary argument lists

You cannot declare a function with same name in a class
def display( intx, inty ):
def display( stringmsg ):



#arbitary argument lists
def display(*args):
assert 0 < len(args) < 3
if len(args) == 2:
x,y = args
# do some thing for intx , intx
print x,y
if len(args) == 1:
stringmsg = args[0]
print stringmsg

#call functions with different number & types of arguments
display(1,2)
display("hello")


"""
simple example to demonstrate operator overloading in IRONPYTHON
"""
class myclass:
def __init__(self,amount=0):
self.amount = amount
def __add__(self, x):
return myclass(self.amount + x.amount)
def __sub__(self, x):
return myclass(self.amount - x.amount)
def __mul__(self, x):
return myclass(self.amount * x.amount)
def __div__(self, x):
return myclass(self.amount / x.amount)

print (myclass(30) + myclass(10)).amount






Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Operator overloading  .  Ironpython  .  Function overloading  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Globalisation
Previous Resource: Creating a Shared Assembly
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

internet fax

Contact Us    Privacy Policy    Terms Of Use