hiding a class property behind a method

simendsjo simendsjo at gmail.com
Sat Feb 22 09:34:40 PST 2014


On 02/22/2014 06:21 PM, luka8088 wrote:
> 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
> }

Just an addition. The following line shows the problem:
   writeln((cast(C)o2).x); // C



More information about the Digitalmars-d-learn mailing list