Hi ,
I have a base class defined as ::
class Base # ( type T = int ) ;
T a ;
function new ( T ip_a ) ;
a = ip_a ;
endfunction
// Has another function defined
function void A ();
....
endfunction
endclass
So now I define an extended class with simply an addition method ::
class Ext # ( type T = int ) extends Base ;
function DISP;
$display("a is %0d",a);
endfunction
endclass
My Question is since the ext class has only an extra method defined , do I need to define a constructor for Ext class ?
Won’t the constructor and function A from Base class be inherited ?
Thanks
In reply to TC_2017:
I suggest trying the code and then looking at my short course on SystemVerilog classes, especially the second session.
In reply to dave_59:
Hi Dave ,
Since base class Constructor has arg. the default Constructor inserted by SV won’t work , hence the compilation error . I tried a few solution and chaining constructor was one of them which worked for above Sample code .
class Ext # ( type T = int ) extends Base # ( T ) ( 10 ) ;
....
endclass
Ext e1 = new() ; // No args. required !!
I have another question using chained Constructor .
I extend uvm_blocking_put_port class ( I add some method to it let’s say ) . Now typically the uvm_blocking_put_port would be used in my code as follows :
class producer extends uvm_component ;
`uvm_component_utils(producer)
uvm_blocking_put_port #(trans) put_port ;
// 3-line Component Constructor here
function void build_phase ( uvm_phase phase ) ;
put_port = new("put_port",this);
endfunction
Now instead I want to use my_blocking_put_port . But I want the declaration to use chain constructor
class my_blocking_put_port #( type T = int ) extends uvm_blocking_put_port # ( T ) ("put_port" , this ) ; // 'this' doesn't work , since no object exists here
class producer extends uvm_component ;
`uvm_component_utils(producer)
my_blocking_put_port #(trans) put_port ;
// NO Constructor here !!
function void build_phase ( uvm_phase phase ) ;
put_port = new(); // Want to use this format .
endfunction
Is there a way to declare my_blocking_put_port using Chained Constructor ?
Does Chained Constructor work only for classes without handle as args. ?.
Thanks