I want to use type T used in parameterized class in overriding new constructor argument. I am getting given error.
Ex. parameterized class
class packet #(type T = int);
T address;
T data ;
Ex. new constructor argument
function new(string name = “wr_rd_sequence”, type T = int);
super.new(name);
endfunction
Error-[SE] Syntax error
Following verilog source has syntax error :
“mem_sequence.sv”, 114: token is ‘T’
function new(string name = “wr_rd_sequence”, type T = int);
In reply to DhavalP:
If the uvm_object class is registered with the factory the format of the constructor is restricted to 1 argument, the name of string type:
function new(string name = "");
super.new(name);
endfunction
If you are using a parameterized class thios does not have any influence on the constructor.
In reply to chr_sue:
I want to remove parameterized class and use constructor overriding instead.
In reply to DhavalP:
You do not have to do that. But it should look like this:
class my_item #(type T = int) extends uvm_sequence_item;
T my_var;
function new(string name = "");
super.new(name);
endfunction
....
endclass
Or you have the parameter in a pkg.
In reply to DhavalP:
You cannot pass a type as an argument to a function/method. You cannot use a type as a value that you use in any kind of assignment. Types can be overriden as parameters at compilation as class specialization; you cannot do this procedurally in simulation. However, it is possible to choose between constructing different specializations using the UVM factory or other similar patterns.
But this is a classic XY Problem. We do not know what known problem led you to think of passing a type as a constructor argument as a possible solution…
In reply to dave_59:
I wanted to pass parameters as variables instead constants so it is not possible using parameterized class and I led to take it as overriding new constructor.
In reply to dave_59:
Hi,
I have same no. of arguments in create as new constructor but still I am getting elab error.
Am I missing something?
function new(string n=“class_new”, int const_d=4, int const_e=4, int T=4);
obj_new[str_name] = class_new::type_id::create(str_name, D, E, tmp_type);
-I-:
-I-:Error-[TMAFTC] Too many arguments to function/task call
-I-:“uvm_object_registry::create(str_name, D, E, tmp_type)”
-I-: The above function/task call is done with more arguments than needed.
-I-:
In reply to DhavalP:
You missed the mention that you can’t change the number of constructor arguments for classes registered with the UVM factory. You can make assignments to the object right after construction.
We still do not know what known problem led you to think of passing a type as a constructor argument as a possible solution.