Why can't static functions be virtual

Benji Smith dlanguage at benjismith.net
Wed Jan 17 13:40:44 PST 2007


James Dennett wrote:
> Quite possible, given one of many possible specifications;
> the difficulty is in making such a specification useful
> rather than brittle and confusing.  The difficulties with
> the concept of virtual statics *are* conceptual, not
> implementation issues.
> 
> If D has one advantage over C++, it is in its relative
> simplicity.  Bogging it down with this kind of conceptual
> murkiness won't help it as a language, IMO.

Good points.

However, one significant benefit that would come from virtual statics 
would be the ability to add static methods to interfaces (I can't tell 
you how often I've wanted to define a static method in an interface!)

And I think the implementation could be pretty straightforward:

1) Instead of a this pointer, static methods always get a ClassInfo pointer.

2) Each ClassInfo would have to put static methods into a StaticVTable, 
rather than just calling those methods by offset.

Personally, I'd be in favor of it. I think it'd be pretty useful.

--benji



More information about the Digitalmars-d mailing list