[ create a new paste ] login | about

Link: http://codepad.org/CYTJzhJc    [ raw code | output | fork ]

D, pasted on Oct 24:
1
2
3
4
5
6
7
8
9
10
11
import std.stdio;

class A   { this(){} int F(){return 0;} this(bool _){this=_?cast(A)new B:cast(A)new C;} }
class B:A { this(){} int F(){return 1;} }
class C:A { this(){} int F(){return 2;} }

void main()
{
   writef("%d\n", (new A(true)).F);
   writef("%d\n", (new A(false)).F);
}


Output:
1
2
1
2


Create a new paste based on this one


Comments: