CoverPoint declaration for Dynamic Array

In reply to dave_59:

Hi Dave, I have a question related to this particular concept.

Suppose my sequence_item (my_sqi) has a variable:

rand bit my_variable; //NOTE: This is a dynamic array whose size i am aware of alll the time
// As it is based on a paramter called “P_NUM”

Now suppose I want to make a functional coverage of this particular variable. So based on the link above and system verilog - Dynamic Coverpoints in Coverage Systemverilog - Stack Overflow

covergroup my_cg with function sample(bit cp_s);
coverpoint cp_s;
endgroup

my_cg m_my_cg1;
m_my_cg1 = new[P_NUM];
foreach (m_my_sqi.my_variable[i]) m_my_cg1[i] = new();
foreach (m_my_sqi.my_variable[i]) m_my_cg1[i].sample(m_my_sqi.my_variable[i]);

Well this is what i have come upto, but this doesn’t work.
Any advices from your end, what am i doing wrong here.