class parent_;
virtual function foo_();
$display("I am parent with member of values ");
endfunction
endclass
class child_ extends parent_;
bit foo_mem;
function foo_();
//##void'(super.foo_()); //##DEBUG: MASTER: regardless of casting/virtual, you may want to uncomment this to see the super effect, when function returns nothing , you should use with void
$display("I am child with member of values %d",foo_mem);
endfunction
endclass
module foo_foo;
parent_ parent_handle;
parent_ parent_handle_1;
child_ child_handle;
initial begin
child_handle = new();
$cast(parent_handle,child_handle); //##DEBUG: MASTER: This is dynamic cast and it can be called as task or func. It will return 0 at RUNTIME if not proper valid casting.
parent_handle_1 = child_handle; //##DEBUG: MASTER: This is static cast and will give COMPILETIME error if not proper
void'(parent_handle_1.foo_()); //##DEBUG: MASTER: when function returns nothing , you should use with void
void'(parent_handle.foo_()); //##DEBUG: MASTER: when function returns nothing , you should use with void
$display("BOTH DYNAMIC AND STATIC CASTING GAVE SAME RESULT");
end
endmodule
//##run results:
/*
ncsim> run
I am child with member of values 0 //##DEBUG: MASTER: --> function called from parent_handle_1, but after casting with child_handle
I am child with member of values 0 //##DEBUG: MASTER: --> function called from parent_handle, but after casting with child_handle
BOTH DYNAMIC AND STATIC CASTING GAVE SAME RESULT
ncsim: *W,RNQUIE: Simulation is complete.
ncsim> exit
*/
No comments:
Post a Comment