I defined some struct
that is the subtype of Parent
.
There is a method I’d like to change for the Child
type but at the same time I want it to call
the same method for Parent type.
What is the correct way to get this behaviour?
abstract type Parent end
mutable struct Child <: Parent
height
end
get_height(x::Parent) = x.height/100
function get_height(x::Child)
get_height(convert(Parent,x)) + 0.01
end
a = Child(180)
get_height(a) # should return 1.81
When I launch this code I get the following error:
StackOverflowError:
Stacktrace:
[1] get_height(::Child) at ./In[18]:9 (repeats 79984 times)
I don’t want to change the name of my method, because there are many Children subtypes with similar methods