In reply to vbabusr:
Calling randomize never constructs a class object or modifies a class variable. Your constraint in invalid.
And it is not sufficient to just declare a class variable—you have to explicitly construct an object and assign its handle to a class variable. You cannot call m_obj.randomize(); until after you have constructed an object with m_obj = new();. And the 4 class objects you declared in main_class need to get constructed either by
class main_class;
rand apr_ab apr_ab_obj;
rand apr_ac apr_ac_obj;
rand apr_ad apr_ad_obj;
rand apr_ae apr_ae_obj;
function new;
apr_ab_obj = new;
apr_ac_obj = new;
apr_ad_obj = new;
apr_ae_obj = new;
endfunction
endclass
Or you can construct the class member after constructing the main_class
class test;
main_class m_obj =new();
apr_ab obj_apr_ab;
function new;
obj_apr_ab = new;
m_obj.apr_ab_obj = obj_apr_ab;
m_obj.randomize();
endfunction
endclass
It is difficult to recommend the best way to code this without knowing what you are trying to accomplish.
https://xyproblem.info