|
|
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;
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 // Increment size task
21 task inc_size();
22 begin
23 this.size ++;
24 $write("%s -> size is incremented\n",this.name);
25 end
26 endtask
27 // Task in class (object method)
28 `PRINT
29 endclass
30
31 A a,b,c;
32
33 initial begin
34 a = new("A");
35 b = new("B");
36 c = new("C");
37 a.inc_size();
38 a.print();
39 b.print();
40 c.print();
41 c.inc_size();
42 a.print();
43 b.print();
44 c.print();
45 end
46
47 endprogram
You could download file class_static.sv here
|