Operator Overloading
# Julia program to illustrate the
# overloading of + and == operators
# Defining a custom type MyNumber
struct MyNumber
value::Int
end
# Overload the + and == operators for MyNumber
Base.:+(x::MyNumber, y::MyNumber) = MyNumber(x.value + y.value)
Base.:(==)(a::MyNumber, b::MyNumber) = a.value == b.value
# Creating MyNumber objects
a = MyNumber(3)
b = MyNumber(4)
z = MyNumber(4)
# Adding both the objects
c = a + b
# Equality of two objects
d = a == b
e = b == z
# Print the results
println("Addition of two structs: $c")
println("Equality of a and b : $d")
println("Equality of b and z : $e")