/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
Possible License(s): LGPL-2.1, Cube, GPL-3.0, 0BSD, GPL-2.0
- module virtual_poly_runme;
- import virtual_poly.NDouble;
- import virtual_poly.NInt;
- import virtual_poly.NNumber;
- void main() {
- // D supports covariant (polymorphic) return types, so this should work like
- // in C++.
- auto d = new NDouble(3.5);
- NDouble dc = d.copy();
- if (d.get() != dc.get()) {
- throw new Exception("Test 1 failed.");
- }
- auto i = new NInt(2);
- NInt ic = i.copy();
- if (i.get() != ic.get()) {
- throw new Exception("Test 2 failed.");
- }
- NNumber n = d;
- auto nd = cast(NDouble) n.copy();
- if (nd.get() != d.get()) {
- throw new Exception("Test 3 failed.");
- }
- }