1 子类调用父类的member: super.computer_crc();
2 子类和父类的handle相互赋值
parent = child;
$cast(child, parent);
3 父类作为函数参数
task proc (parent_class tr);
...
endtask
...
proc(child_tr);
4 多态:用virtual task/function实现
a. 父类中有proc task, 子类中也有proc task,tr.proc()会使用父类还是子类的呢?
这取决于tr的类型,与是否virtual无关。如果tr的类型是父类,那么使用父类中的proc,否则使用子类的proc
b. 但当父类作为function的参数时就不一样了
task compute (parent_class tr);
...
tr.proc();
endtask
...
computer(child); //如果proc不是virtual, 则一定调用父类的proc;
//如果要调用子类的proc,那么proc要声明为virtual
5 在class定义的外面实现task和function
class parent;
...
external virtual function void proc();
endclass
function void parent::proc();
...
endfunction
6 parameterized class
class stack #(type T=int);
local T item;
...
external virtual function T pop();
...
endclass
stack #(bit[31:0]) addr_stack; 或 typedef stack #(bit[31:0]) stack32;
stack #(transaction) tr_stack; typedef stack #(transaction) stack_tr;
stack32 addr_stack;
stack_tr tr_stack;
7 声明顺序是C1, C2,但C1中要用C2,需要使用typedef
typedef class C2;
class C1;
...
C2 obj;
...
endclass
class C2
...
endclass
8. static变量