Weird behavior of "this" in a subclass, I think?

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jul 16 02:16:44 PDT 2015


On 2015-07-16 09:46, Jonathan M Davis via Digitalmars-d-learn wrote:

> I've never heard of a language that overloaded member variables, and given
> how class polymorphism works, I don't see how it would even be possible
> without making it so that all accesses to a variable actually call a
> function to access it, which would needlessly inefficient (polymorphism
> works by looking up the correct function in the class' virtual table, and
> the call site isn't going to know at compile time what class it's actually
> operating on, so all of that has to be done at runtime). And if you really
> want something approximating overriding variables, then you can just use
> property functions to access the variable rather than accessing it directly,
> and then you can override the property functions.

In Scala all public instance variables are implemented as methods, if I 
recall correctly.

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list