zoukankan      html  css  js  c++  java
  • UVM Primer

      class rectangle;
        int length;
        int width;
        
        function new(int l, int w);   
          length = l;
          width  = w;
        endfunction
        
        function int area();
          return length * width;
        endfunction
      endclass
      
      class square extends rectangle;
      
        function new(int side);  //我们重载了new()构造函数,这个square版的new()只有一个参数 : 边长。
          super.new(.l(side), .w(side));  //super关键字指示编译器来显式的引用父类中定义的数据成员和方法。
        endfunction
      
      endclass
      
      module top_class ;
        rectangle rectangle_h;
        square    square_h;
        
        initial begin
        
          rectangle_h = new(.l(50),.w(20));
          $display("rectangle area: %0d", rectangle_h.area());
          
          square_h = new(.side(50));
          $display("square area: %0d", square_h.area());
          //我们声明了square的一个变量然后用 new() 来创建对象。我们调用了new()两次,但是两次运行的是不同的版本 : 一个是rectangle的一个是 square的。编译器知道所有 new() 的调用跟表达式左边的变量类型都是相关的。
        end
      endmodule
  • 相关阅读:
    函数
    registry搭建及镜像管理-harbor
    用户输入和while 循环
    dockerfile
    字典,set
    if 语句
    alpine操作
    循环:列表,元组
    列表
    docker跨主机通信-overlay
  • 原文地址:https://www.cnblogs.com/yiyedada/p/12365532.html
Copyright © 2011-2022 走看看