Hi all,
I'm trying to implement something that allows user to derive a new type
from my abstract type and also add new behavior to the methods operating on
those new types. For example, the following code snippet:
---------------------------------------------x-------------------------------------
module Foo
abstract TBase
function myfunc(a::TBase)
@printf "base function is called\n"
end
function invoke(a::TBase)
myfunc(a)
end
export TBase
#export myfunc
export invoke
end
using Foo
type TSub <: TBase
end
function myfunc(a::TSub)
@printf "override function is called\n"
end
foo = TSub()
invoke(foo)
---------------------------------x---------------------------------
my intention is that when user call "invoke" with a subtype, the "myfunc"
defined for this subtype should be called. Everything works fine if I
didn't put my internal stuff inside a module. However, after I put my stuff
in a module, it doesn't work: only the original base method is called. I
have tried to export "myfunc" or not, but it doesn't change.
Can anyone point me out how should I work around this or what is the
correct way of doing this? I suppose this is a quite common scenario as in
traditional OOP, we allow the user to provide derived type with customized
behavior on that type.
Best,
Chiyuan