Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过约束演示OOPS的Systemverilog多态性特性_Oop_System Verilog - Fatal编程技术网

通过约束演示OOPS的Systemverilog多态性特性

通过约束演示OOPS的Systemverilog多态性特性,oop,system-verilog,Oop,System Verilog,我正在检查我对约束多态性的理解。我编写了一个示例代码 class parent; rand int unsigned a; constraint a_c { a < 1000;} function print(); $display("The randomized data is %d\n", a); endfunction endclass class child extends parent; constraint a_c { a > 50;} en

我正在检查我对约束多态性的理解。我编写了一个示例代码

class parent;
  rand int unsigned a;
  constraint a_c { a < 1000;}
  function print();
    $display("The randomized data is %d\n", a);
  endfunction
endclass

class child extends parent;
  constraint a_c { a > 50;}
endclass

module m;
  child c = new();

  initial begin
    c.randomize();
    c.print;
  end
endmodule

这里出了什么问题?

这是一个满足
约束a_c{a>50;}
的有效结果,因为您扩展了约束
a_c
,它覆盖了基类中的约束。如果希望约束是可添加的,则需要为其指定与基类不同的名称


顺便说一句,我建议在提到OOP继承时避免使用“父”和“子”这两个术语。这些术语意味着不同的对象。改用基类/超级类和派生类/扩展类

这是一个满足
约束a_c{a>50;}
的有效结果,因为您扩展了约束
a_c
,它覆盖了基类中的约束。如果希望约束是可添加的,则需要为其指定与基类不同的名称


顺便说一句,我建议在提到OOP继承时避免使用“父”和“子”这两个术语。这些术语意味着不同的对象。改用基类/超级类和派生类/扩展类

看起来像是预期的行为。-->与任务和函数一样,基类中同名的派生类中的约束将重写基类约束。看起来像预期的行为。-->与任务和函数一样,基类中具有相同名称的派生类中的约束将重写基类约束。+1仅用于此…”顺便说一句,我建议在引用OOP继承时避免使用术语“父”和“子”。这些术语表示不同的对象。“+1仅用于此…”。。。“顺便说一句,我建议在提到OOP继承时避免使用“父”和“子”这两个术语。这些术语意味着不同的对象。”
The randomized data is 2567677