ManMe Posted March 17, 2013 Report Share Posted March 17, 2013 What is the difference between storing handle in array like, ex_obj obj[5]; ex_obj obj1; for (i=0,i<5;i++) begin obj1 = new(); obj = obj1; end and storing objects in an array? ex_obj obj[5]; ex_obj obj1; obj1 = new (); for (i=0,i<5;i++) begin obj = new(); obj = obj1; end which is an efficient way to do? Quote Link to comment Share on other sites More sharing options...
dave_59 Posted March 18, 2013 Report Share Posted March 18, 2013 You never store a class object in a class variable. It's always the class handle to the class object that is stored in the class variable. Both examples store class handles in an array of class variables. The first example stores a class handle in an intermediate class variable (obj1) before making an second assignment of the intermediate variable to an element of the array (obj). Each time through the loop creates a new object whose handle is stored in each element of the array. The second example stores a class handle in an intermediate class variable (obj1) only once. Then each time through the loop you assign a new object handle to an element of the array (obj) and then overwrite the handle with the handle stored in obj1. So at the end of the loop, you have 5 elements of the array obj referencing a single object. I think what you want is this: ex_obj obj[5]; foreach (obj) begin obj = new(); end Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.