Too few arguments in new function

Here is my code.

  1. my_base_subscriber.svh file

virtual class my_base_subscriber #(type T) extends uvm_subscriber #(T);

    `uvm_component_utils(my_subscriber#(T))

    function new(string name, uvm_component parent);
        super.new(name, parent);
    endfunction : new

endclass : my_base_subscriber

  1. my_work_subscriber.svh file

class my_work_subscriber extends my_base_subscriber #(my_trans);

    `uvm_component_utils(my_work_subscriber)
    int idx;
    function new(string name, uvm_component parent, int idx);
        super.new(name, parent);
        this.idx = idx
    endfunction : new

endclass : my_work_subscriber

  1. in the my_env.svh file

class my_env extends uvm_env;
   ...
   my_work_subscriber m_work_sub[4];
   ...
   function void build_phase(uvm_phase phase);
     for(int i = 0; i < 4; i++) begin
       m_work_sub[i] = new($sformatf("m_work_sub_%d", i), this, i);
     end
   endfunction : build_phase
   ...
endclass : my_env

Then I met the compile error as shown below.

Error-[TFAFTC] Too few arguments to function/task call
$UVM_HOME/src/base/uvm_registry.svh, 66
“my_work_subscriber::new(name, parent)”
The above function/task call is not done with sufficient arguments.

In reply to zz8318:

You can’t modify the constuctors used for uvm_components due to the way that they are used within the factory. You will need to add another function to add the index to your subscriber.

In reply to cgales:

Do you mean the new function can not be changed in my class ? I only keep use name and parent as the parameter for this function ?

In reply to zz8318:

You cannot register a class with the factory AND change the class construtor’s arguments. The factory adds code that calls the constructor, and it only knows about the two arguments name and parent.

In reply to dave_59:

got it. Thank you both.