hiding a class property behind a method
Ali Çehreli
acehreli at yahoo.com
Sat Feb 22 09:41:58 PST 2014
On 02/22/2014 09:21 AM, luka8088 wrote:> It seems to me that the
following code should be illegal, but I am
> uncertain of it so I am posting here for a confirmation before I post it
> on bug tracker:
>
>
> http://dpaste.dzfl.pl/dae728734cc6
>
>
> import std.stdio;
>
> class A {
> string x () { return "A"; };
> }
>
> class B : A {
> override string x () { return "B"; };
> }
>
> class C : A {
> string x = "C"; // should this be illegal?
> }
>
> void main () {
> A o1 = new B();
> writeln(o1.x); // B
>
> A o2 = new C();
> writeln(o2.x); // A
> }
>
The code uses the two objects through the A interface and x() is a
virtual function on that interface.
When the C interface is used then we get C.x, which happens to be hiding
the x() function of the base class.
It looks normal to me.
Ali
More information about the Digitalmars-d-learn
mailing list