是否可以将type
参数传递给函数,以便create_eclass*
函数只能通过将类类型参数传递给它来编写一次?
class bclass;
virtual function void print();
$display("Base Class");
endfunction
endclass
class eclass1 extends bclass;
function void print();
$display("Extended Class1");
endfunction
endclass
class eclass2 extends bclass;
function void print();
$display("Extended Class2");
endfunction
endclass
program Test ;
bclass q[$];
function create_eclass1();
bclass b;
eclass1 e;
e=new();
$cast(b,e);
q.push_back(e);
endfunction
function create_eclass2();
bclass b;
eclass2 e;
e=new();
$cast(b,e);
q.push_back(e);
endfunction
initial
begin
create_eclass1();
create_eclass2();
foreach(q[i]) q[i].print();
end
endprogram