www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - static interface function

Hello all,

It seems to me that a static function within an interface is not correct. But
with  DMD v0.109 you can create an interface with a static function. Then when
that interface is implemented, you can include that same function in the
implementing class. That function can be called from the namespace of the class
and it all works. If you try to call that function from the namespace of the
interface, it will compile but fail to link and find that interface static
function. You can even not put that function in the class, but have it in the
interface, and call the function from the namespace of the class. Once again it
will compile (without an undefined property error), but fail to link.

This leads me to a thought though. It would be pretty damn cool if you could
have a 'singleton' static interface function. For interfaces that follow the
singleton model. For example, have an interface that is shared between two
different binaries, but each binary has its own implementation. And having the
standard 'getInstance' style function to get a reference to a static instance
variable (the variable would deffinitely not be part of the interface, but part
of the implementation). It would require making sure that that symbol is only
found once for the link of a binary. Otherwise you could choose between

Perhaps this was intended with D for the 'static' keyword? :)

Chris Newton
Dec 26 2004