SV: dynamic casting with cast - complete - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

208


34
 
1
class parent_trans;
2
  bit [31:0] data;
3
  int id;
4
  
5
  function void display();
6
    $display("Base: Value of data = %0d, id = %0d", data, id);
7
  endfunction
8
endclass
9
10
class child_trans extends parent_trans;
11
   
12
  function void display();
13
    $display("Child: Value of data = %0d, id = %0d", data, id);
14
  endfunction
15
endclass
16
17
module class_example;
18
  initial begin
19
    parent_trans p_tr;
20
    child_trans c_tr;
21
    c_tr = new();
22
23
    p_tr = c_tr; // or $cast(p_tr, c_tr);
24
    $cast(c_tr, p_tr);
25
26
    p_tr.data = 10;
27
    p_tr.id   = 1;
28
    
29
    c_tr.data = 5;
30
    c_tr.id   = 2;
31
    
32
    c_tr.display();
33
  end
34
endmodule
xxxxxxxxxx
1
 
1
// Code your design here
2
1480 views and 0 likes     
 
Example of dynamic casting - complete

Example of dynamic casting - complete

150:0