PageRenderTime 26ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/test-suite/d/virtual_poly_runme.1.d

#
D | 27 lines | 21 code | 4 blank | 2 comment | 6 complexity | 8e4d05a9e7b5ccd6cef1a12565c11e41 MD5 | raw file
 1module virtual_poly_runme;
 2
 3import virtual_poly.NDouble;
 4import virtual_poly.NInt;
 5import virtual_poly.NNumber;
 6
 7void main() {
 8  // D supports covariant (polymorphic) return types, so this should work like
 9  // in C++.
10  auto d = new NDouble(3.5);
11  NDouble dc = d.copy();
12  if (d.get() != dc.get()) {
13    throw new Exception("Test 1 failed.");
14  }
15
16  auto i = new NInt(2);
17  NInt ic = i.copy();
18  if (i.get() != ic.get()) {
19    throw new Exception("Test 2 failed.");
20  }
21
22  NNumber n = d;
23  auto nd = cast(NDouble) n.copy();
24  if (nd.get() != d.get()) {
25    throw new Exception("Test 3 failed.");
26  }
27}