|
|
|
|
|
|
|
|
|
|
|
|
Static class methods
|
|
|
Methods can be declared as static. A static method is subject to all the class scoping and access rules, but behaves like a regular subroutine that can be called outside the class, even with no class instantiation. A static method has no access to nonstatic members (class properties or methods), but it can directly access static class properties or call static methods of the same class. Access to nonstatic members or to the special this handle within the body of a static method is illegal and results in a compiler error. Static methods cannot be virtual. |
|
|
|
|
|
|
|
|
|
|
|
Example - Static class methods
|
|
|
|
|
|
1 `define PRINT task print (); \
2 begin \
3 $write("%s -> Size is %0d\n",this.name, this.size); \
4 end \
5 endtask
6
7 program class_static_method;
8 // Class with constructor, with no parameter
9 class A;
10 // Make size as static
11 static integer size;
12 string name;
13 // Constructor
14 function new (string name);
15 begin
16 this.name = name;
17 this.size = 0;
18 end
19 endfunction
20 // static Increment size task
21 static task inc_size();
22 begin
23 size ++; // Ok to access static member
24 $write("size is incremented\n");
25 // Not ok to access non static member name
26 //$write("%s -> size is incremented\n",name);
27 end
28 endtask
29 // Task in class (object method)
30 `PRINT
31 endclass
32
33 A a;
34
35 initial begin
36 a = new("A");
37 a.inc_size();
38 a.print();
39 end
40
41 endprogram
You could download file class_static_method.sv here
|
|
|
|
|
|
Simulation - Static class methods
|
|
|
|
|
|
size is incremented
A -> Size is 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Copyright © 1998-2014 |
Deepak Kumar Tala - All rights reserved |
Do you have any Comment? mail me at:deepak@asic-world.com
|
|