|
楼主 |
发表于 2022-5-17 15:02:28
|
显示全部楼层
`timescale 1ns/1ns
class parent;
int A = 2;
virtual function void cprintf();
$display("hello word");
endfunction
function new();
endfunction
endclass
class child extends parent;
int B = 4;
function new();
endfunction
function void cprintf();
$display("I'm child,hello word");
endfunction
endclass
module ptest;
parent a;
child b,b1;
initial begin
b = new(); //子类对象
a=b;
$display("child A = %d",b1.B);
void'($cast(b1,a));
$display("child A = %d",b1.B);
end
endmodule
懂了,谢谢大佬,明白了cast
|
|