007 Class(类)

类(Class)

  • Object:类实例后的对象
  • Object members:成员
  • Constructors:构造函数
  • Static class members:静态类成员
  • Assignments:赋值
  • Inheritance and subclasses:继承和子类
  • this and super:指针
  • Data hiding and encapsulation
  • Constant class properties:常量类属性
  • Abstract classes and virtual methods:抽象类和虚拟方法
  • Class scope resolution operator:类范围解析运算符
  • Parameterized classes:参数化类
program class_t;
  class packet;
     // members in class
     integer size;
     integer payload [];
     integer i;
     // Constructor
     function new (integer size);
       begin
         this.size = size;
         payload = new[size];
         for (i=0; i < this.size; i ++) begin
           payload[i] = $random;
         end 
       end 
     endfunction
     // Task in class (object method)
     task print ();
       begin
         $write("Payload : ");
         for (i=0; i < size; i ++) begin
           $write("%x ",payload[i]);
         end
         $write("\n");
       end 
     endtask
     // Function in class (object method)
     function integer get_size();
       begin
         get_size = this.size;
       end
     endfunction
   endclass

   packet pkt;

   initial begin
     pkt = new(5);
     pkt.print();
     $display ("Size of packet %0d",pkt.get_size());
   end

endprogram

其实类似C++,具体的后续再补充

你可能感兴趣的:(SystemVerilog)