|
|
The user-defined data type, class, is composed of data members of valid OpenVera data types (known as properties) and tasks or functions (known as methods) for manipulating the data members. The properties and methods, taken together, define the contents and capabilities of a class instance or object. |
|
|
1 class packet {
2 // Elements in class
3 integer size;
4 integer payload [*];
5 integer i;
6 // Constructor
7 task new (integer size) {
8 this.size = size;
9 payload = new[size];
10 for (i=0; i < this.size; i ++) {
11 payload[i] = random();
12 }
13 }
14 // Task in class
15 task print () {
16 printf("Payload : ");
17 for (i=0; i < size; i ++) {
18 printf("%x ",payload[i]);
19 }
20 printf("\n");
21 }
22 // Function in class
23 function integer get_size() {
24 get_size = this.size;
25 }
26 }
27
28 program class_t {
29 packet pkt = new(5);
30 pkt.print();
31 printf ("Size of packet %d\n",pkt.get_size());
32 }
You could download file class_t.vr here
|