Hi Dave,
I watched one of your session on OOP for down casing. I tried very simple example, state below, but I am seeing error with VCS and Modelsim, complaining about Dynamic Cast Failure. I am unable to understand why it is not able to cast parent handle to child?
class A;
int a=1;
endclass
class B extends A;
int b=2;
endclass
class C extends B;
int c=3;
endclass
module test();
A a = new();
B b;
C c;
initial begin
// Down casting
$cast(c, a);
$display(“Print c.c %0d”, c.c);
end
endmodule
Error with VCS:
Error-[DCF] Dynamic cast failed
dave.sv, 27
Casting of source class type ‘A’ to destination class type ‘C’ failed due to
type mismatch.
Please ensure matching types for dynamic cast
Can you help me understand why it is unable to down cast?