PageRenderTime 13ms CodeModel.GetById 1ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

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

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