I expected my_child to inherit the say_hello function from my_parent in the following code, but it did not.
Can someone explain to me what exactly parent argument does?
class my_parent extends uvm_component;
`uvm_component_utils(my_parent);
function new(string name = "my_parent", uvm_component parent);
super.new(name, parent);
endfunction: new
function void say_hello;
$display("Hello, UVM!");
endfunction: say_hello
endclass: my_parent
/*========================================*/
class my_child extends uvm_component;
`uvm_component_utils(my_child);
function new(string name = "my_child", uvm_component parent);
super.new(name, parent);
endfunction: new
endclass: my_child
/*========================================*/
module top;
my_parent p;
my_child c;
initial begin
p = my_parent::type_id::create("p", null);
c = my_child::type_id::create("c", p);
c.say_hello;
end
endmodule: top
>Solution :
You should extend the child class from the parent class instead of uvm_component when you want to inherit from the parent class. Change:
class my_child extends uvm_component;
to:
class my_child extends my_parent;
The parent variable is explained in the UVM Class Reference document under uvm_component.