System verilog 可以在assign语句外调用SystemVerilog中的new吗?
这就是我通常在SystemVerilog中调用System verilog 可以在assign语句外调用SystemVerilog中的new吗?,system-verilog,System Verilog,这就是我通常在SystemVerilog中调用new的方式: class A; endclass A a = new(); 但有时,我不需要一个本地对象,我只想将它直接发送到一个函数,该函数采用a。这里有没有明确调用新函数的方法: function use_a(A obj); endfunction use_a(new()); // <--- How to write this call to specify which new to call? use_a(A::new());
new
的方式:
class A;
endclass
A a = new();
但有时,我不需要一个本地对象,我只想将它直接发送到一个函数,该函数采用a
。这里有没有明确调用新函数的方法:
function use_a(A obj);
endfunction
use_a(new()); // <--- How to write this call to specify which new to call?
use_a(A::new()); // <--- new not expected here :(
功能使用(obj);
端功能
使用_a(new());// 不幸的是,SystemVerilog的语法不允许这样做。特殊的new
方法不是静态方法,并且由于类内存管理的定义方式,类句柄必须存在于某些变量中。您可以通过围绕静态方法包装new
来解决此问题:
class A;
static function A create();
create = new();
endfunction
endclass
...
use_a(A::create());
顺便说一句,UVM在BCL中有create
方法,你几乎不需要直接调用new()
。我相信答案是否定的。但你为什么要这么做呢?为什么不在函数内部调用new呢?