我有一个不能更改的函数,它需要输入ExpectedType。
function some_function(some_parameter::ExpectedType)
....
some implementation
....
end我想传递我的OtherType类型的对象。
我决定从OtherType继承ExpectedType。
struct OtherType <: ExpectedType end但是我收到了一个错误:ERROR: invalid subtyping in definition of OtherType
发布于 2022-02-08 09:37:24
ExpectedType编写一个构造函数,该构造函数以OtherType为参数,然后调用OtherType。此外,您还可以定义:
SourceModuleName.some_function(x::OtherType) = some_function(ExpectedType(x))这样您就不必显式地调用构造函数。
https://stackoverflow.com/questions/71031503
复制相似问题