Reputation: 1055
I have a function that I can't change and it expects type ExpectedType
.
function some_function(some_parameter::ExpectedType)
....
some implementation
....
end
I want to pass my object of type OtherType
.
I decided to inherit OtherType
from ExpectedType
.
struct OtherType <: ExpectedType end
But I'm getting an error: ERROR: invalid subtyping in definition of OtherType
Upvotes: 3
Views: 260
Reputation: 69829
ExpectedType
that takes OtherType
as argument and then call some_function(ExpectedType(your_object))
.Also then you could define:
SourceModuleName.some_function(x::OtherType) = some_function(ExpectedType(x))
so that you do not have to call the constructor explicitly.
Upvotes: 6