在同一个 class 中包含的另一个静态成员函数中使用静态成员函数是否合理?
Is it reasonable to use a static member function within another static member function contained within the same class?
我正在尝试重新组织一些代码,使其能够自我记录。如果我有一个 class 我不打算实例化,而是想调用以执行与同一想法相关的各种任务,我可以创建简单的静态成员函数,然后由以后的静态成员函数调用(或者我的任务)?
class foo;
static protected bit [7:0] Data_A;
static protected bit [7:0] Data_B;
static task bar();
/* Use to print out info. in Data_A and Data_B. */
endtask : bar
static task FooBar();
/* Perform some manipulations on Data_A and Data_B. */
bar();
endtask : FooBar
endclass : foo
然后在我的程序中我会做类似的事情:
program automatic main();
initial
begin
foo::FooBar();
$finish;
end
endprogram
听起来像吗?感谢您的时间。我一直在看IEEE System-Verilog标准,但是这种情况好像没有上来
编辑:我需要使用“this”关键字,还是为实例化 classes 预留以引用自身?
能够从另一个调用 class 的一个静态方法是非常合适的。您不使用 this
前缀来调用静态方法。您可以在调用前加上 foo::bar()
只是为了让 reader 更清楚您正在调用静态方法,但语言不需要它。
任何你不想构建的 class 应该声明为
virtual class foo;
您甚至可以通过将构造函数声明为
来更进一步
local function new; endfunction
这使人们无法扩展和构建它,但这可能有点矫枉过正。
最后一个建议:您正在做的事情可能更适合 package
package automatic foo;
bit [7:0] Data_A;
bit [7:0] Data_B;
task bar();
/* Use to print out info. in Data_A and Data_B. */
endtask : bar
task FooBar();
/* Perform some manipulations on Data_A and Data_B. */
bar();
endtask : FooBar
endpackage : foo
module automatic main();
initial
begin
foo::FooBar();
$finish;
end
endmodule
我正在尝试重新组织一些代码,使其能够自我记录。如果我有一个 class 我不打算实例化,而是想调用以执行与同一想法相关的各种任务,我可以创建简单的静态成员函数,然后由以后的静态成员函数调用(或者我的任务)?
class foo;
static protected bit [7:0] Data_A;
static protected bit [7:0] Data_B;
static task bar();
/* Use to print out info. in Data_A and Data_B. */
endtask : bar
static task FooBar();
/* Perform some manipulations on Data_A and Data_B. */
bar();
endtask : FooBar
endclass : foo
然后在我的程序中我会做类似的事情:
program automatic main();
initial
begin
foo::FooBar();
$finish;
end
endprogram
听起来像吗?感谢您的时间。我一直在看IEEE System-Verilog标准,但是这种情况好像没有上来
编辑:我需要使用“this”关键字,还是为实例化 classes 预留以引用自身?
能够从另一个调用 class 的一个静态方法是非常合适的。您不使用 this
前缀来调用静态方法。您可以在调用前加上 foo::bar()
只是为了让 reader 更清楚您正在调用静态方法,但语言不需要它。
任何你不想构建的 class 应该声明为
virtual class foo;
您甚至可以通过将构造函数声明为
来更进一步local function new; endfunction
这使人们无法扩展和构建它,但这可能有点矫枉过正。
最后一个建议:您正在做的事情可能更适合 package
package automatic foo;
bit [7:0] Data_A;
bit [7:0] Data_B;
task bar();
/* Use to print out info. in Data_A and Data_B. */
endtask : bar
task FooBar();
/* Perform some manipulations on Data_A and Data_B. */
bar();
endtask : FooBar
endpackage : foo
module automatic main();
initial
begin
foo::FooBar();
$finish;
end
endmodule