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