Passing a value (from int variable) as parameter inside parameterized class while creating it

I want to pass pass parameter “num_ports” into parameterised class as below. I am setting num_ports inside uvm_config_db from tb_top file & getting it inside build phase of env file as below.

code inside
int num_ports;

  1. uvm_config_db#(int)::get(uvm_root::get(), “*”, “num_ports”, num_ports);
  2. h_abc = abc#(num_ports, 8)::type_id::create(“h_abc”, this);

Above line number 2 gives an compile error pointing to num_ports as: xmvlog: *E,NOTPAR (/…/…/…/.sv,315|59): Illegal operand for constant expression [4(IEEE)].

My class definition:
class abc#(int NUM_PORTS=8, int CNT=1) extends base_class;

May I know why I am getting this error & fix for the same?


In reply to Shailesh Gajjar :

The parameter overrides of a parameterized class must be defined as other parameters or constant literals; they can not be variables.

We need to see what you plan to do with NUM_PORTS to suggest an alternative.

In reply to dave_59:

Hi Dave, I was using local variable to override parameter which is not allowed as you confirmed. I have fixed the issue by declaring new parameter to override it into parameterized class.

Thanks for the feedback.

Shailesh G.