File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -1036,18 +1036,24 @@ $(H3 $(LNAME2 cast_class, Class References))
1036
1036
really is a downcast. $(D null) is the result if it isn't.
1037
1037
)
1038
1038
1039
+ $(SPEC_RUNNABLE_EXAMPLE_RUN
1039
1040
-------------
1040
- class A { ... }
1041
- class B : A { ... }
1041
+ class A {}
1042
+ class B : A {}
1042
1043
1043
- void test(A a, B b )
1044
+ void main( )
1044
1045
{
1045
- B bx = a; // error, need cast
1046
- B bx = cast(B) a; // bx is null if a is not a B
1047
- A ax = b; // no cast needed
1048
- A ax = cast(A) b; // no runtime check needed for upcast
1046
+ A a = new A;
1047
+ //B b = a; // error, need cast
1048
+ B b = cast(B) a; // b is null if a is not a B
1049
+ assert(b is null);
1050
+
1051
+ a = b; // no cast needed
1052
+ a = cast(A) b; // no runtime check needed for upcast
1053
+ assert(a is b);
1049
1054
}
1050
1055
-------------
1056
+ )
1051
1057
1052
1058
$(P In order to determine if an object $(D o) is an instance of
1053
1059
a class $(D B) use a cast:)
You can’t perform that action at this time.
0 commit comments