Regarding class array inside another class

In reply to megamind:

When dealing with container classes in SystemVerilog, you need to understand the differences between “shallow” and “deep” access. When it comes to things like copying, comparing, and printing a hierarchy of contained classes, you must provide the necessary methods that traverse the hierarchy. That is what’s call a “deep” dive into the class. Otherwise, all you see is the top-level container, or “shallow” view of the class.

class Container;
  Register regs[];
  string m_name;
 
  function new (string name);
    m_name = name;
    regs = new[3];
    regs[0] = new("first");
    regs[1] = new("second");
    regs[2] = new("third");
  endfunction
  
  function void print();
    $display(m_name);
    foreach(regs[i]) regs[i].print();
  endfunction
endclass
 
module tb;
  Container c;
 
  initial begin
    c = new("MainContainer");
    $display ("-------- Initial Values --------");
    c.print();
  end
endmodule