Parameterised members of a class assigning new value

Barath,

Please use code tags to format your code.

Parameters cannot be procedurally overridden. Parameters are compile time constants that can be used in the definition of other types. The compiler requires that certain expressions be compile time constants so it can either generate the code to simulate it, or synthesize it into hardware. You can only override a class parameter in the declaration of a class variable or in the declaration of another class type using a typedef.

package abc;
  class basic #(int My_var); // It is preferable to put parameters in the class header
    bit [My_var:0] member; // type of member is determined at compile time
  endclass
endpackage : abc

module top; // You should not reuse the same name to represent different things
 
abc::basic #(.My_var(2)) bas1;
abc::basic #(.My_var(8)) bas2;

  initial begin
    bas1=new();
    bas2=new();
    $display("bas1.member=%b",bas1.member); // displays 3-bits
    $display("bas2.member=%b",bas2.member); // displays 9-bits
  end
endmodule : top

You may want to read my DVcon paper about parameterized classes.