I'm trying to create a dynamic array of type int and using a for loop trying to assign a value to each element of the array. I'm getting a syntax error while doing so

cores=new[no_cores] is procedural code; it can’t hang around with variable declarations.

class myclass;

rand int no_of_transactions;
int no_cores = 8;

int no_of_transactions_max = 10;
int no_of_transactions_min = 1;

int cores;

function void init_memory();
cores = new[no_cores]; // <---- my new home!
endfunction

endclass