class configuration;
int numoftxns;
enum int{b_wr,b_rd,wr_rd}CMD_TYPE; // burst write, burst read, write followed with read
enum int{d_random,d_incr,d_decr,d_userpat,d_constant}DATA_TYPE;
enum int{a_random,a_incr,a_decr,a_userpat,a_constant}ADDR_TYPE;
endclass
n enum variable ‘this.cfg.CMD_TYPE’ may only be assigned the same enum typed variable or one of its values. Value ‘8’ requires an explicit cast.
An enum variable ‘this.cfg.DATA_TYPE’ may only be assigned the same enum typed variable or one of its values. Value ‘10’ requires an explicit cast.
An enum variable ‘this.cfg.ADDR_TYPE’ may only be assigned the same enum typed variable or one of its values. Value ‘10’ requires an explicit cast.
There are several problems with your code, and the previous two replies are incorrect.
Why do you define a set of enum variables and proceed to assign them with values that are not one of the enumerated labels? This is illegal even if the integral value matches the encoded label value. But SystemVerilog allows you to use an explicit cast to allow the variable to hold an illegal value. However, since you used an anonymous enum type to define your variables, there is no type name to use with the cast.
It is always a good idea to use a typedef with an enum. Then you can create multiple variables with the same type to pass around. An anonymous enum can only be used for one variable.
So to fix your code, you need to either change the RHS of the enum variable assignments from numeric values to one of the declared enum label names, or you need to define a typedef for the enum and use an explicit cast.