How Class can contain Handles to Other Objects

Here, i am illustrating an example where one of the class  is defined as an object inside another class and created during the generation

      class  mouth;
            int     teeth;
            function  new (int teeth);
                  this.teeth   =  teeth;
            endfunction
       endclass

       class  animal;
              int     age;
              mouth  m_h;           // handle defined for the class mouth but not yet created
              function new (int age, teeth);
                    this.age     =  age;
                    m_h          = new(teeth);
              endfunction
        endclass

        module top;
                animal     a_h;
                initial begin
                          a_h    =  new (1, 4);
                 end
         endmodule
        
               

Comments

Popular posts from this blog

What is Class based Randomization and how do we define ?

How Disable Constraints in SystemVerilog

How do we define Weighted Distribution Constraint in SystemVerilog