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

Reply via email to