u24c02
Advanced Member level 1
What is the benefit of using polymorphism in systemverilog?
I'd like to know "practically" the benefit of virtual used in systemverilog.
Here is simple example,
As I understand from here, virtual is just can make overriding to another function. and If I want to use polymorphism then I have to use the 'virtual'.
BTW, I can't find any other benefits that using the polymorphism
Does anyone let me know what is the benefit of using the polymorphism ?
I'd like to know "practically" the benefit of virtual used in systemverilog.
Here is simple example,
Code:
program main();
class A;
virtual task disp();
$display("This is a A class");
endtask
class A_1 extend A;
task disp();
$display("This is a A_1 class");
endtask
endclass
class A_2 extend A;
task disp();
$display("This is a A_2 class");
endtask
endclass
class A_3 extend A;
task disp();
$display("This is a A_3 class");
endtask
endclass
...
A a;
A_1 a_1;
A_2 a_2;
A_3 a_3;
initial begin
a = new();
a_1 = new();
a_2 = new();
a_3 = new();
a.disp();
a = a_1;
a.disp();
a = a_2;
a.disp();
a = a_3;
a.disp();
end
endprogram
As I understand from here, virtual is just can make overriding to another function. and If I want to use polymorphism then I have to use the 'virtual'.
BTW, I can't find any other benefits that using the polymorphism
Does anyone let me know what is the benefit of using the polymorphism ?