前言
今天和某大佬交流了下System Verilog中的OOP属性,本来自己对这块一直感觉还比较良好,但是跟大佬交流后才发现原来要学的还有很多。
拓展类的构造函数
具体内容可以参考"IEEE system verilog标准" 8.7 "constructors"/8.8 "typed constructor calls"以及绿皮书8.1.4节"拓展类的构造函数"。
要点1:无论是否super.new,子类new都会自动调用父类的new;
class father;
int flow_id;
function new(int id = 100);
$display("new father");
flow_id = id;
endfunction: new
endclass: father
class son extends father;
function new();
$display("new son, flow_id='d%0d", flow_id);
endfunction: new
endclass: son
//env
...
begin
father obj_fa1;
father obj_fa2;
son obj_sn1;
son obj_sn2;
obj_fa1