I want to use string as a parameter in parameterized class . I could not do it directly like we do for other datatypes. Can we use typecasting or is there any other method to do it?

In reply to Priyanka_1996:

I am not sure about the intent of code. But instead of hard coding to int, we can use type A in the set/get function itself. The code works fine for me after the following changes.

class sn_oops #(type A = int);
A data;

task set(A i); // Use type A
data = i;
$display("The value of data is --> %0d",data);
endtask: set

function A get();  // Use type A
return data;
endfunction: get

// ... 
sn_oops #(bit[2:0]) sn_h1; 
sn_oops #(string) sn_h2;
//...
sn_h2.set($sformatf("%0s","270")); // sformatf is just for illustration purpose.
//...

// Output:
The value of data is --> "270"
the value of sn_h2 is '{data:"270"}

Also, using ā€œ%0pā€ instead of ā€œ%0dā€ in the functions will be helpful.

A similar example is shown in this thread.