We have method overriding in system verilog, where the method in derived class can override the base class’s method. Both the methods should be of same name and same signature.
Do we have method overloading in system verilog? I mean does SV supports this concept?
If it is supported, can any body tell me the context in testbench or test development?
AFAIK “overloading” is not available in SV (unlike in VHDL for instance). Maybe if you explain what you need, we can help you find a way to do it in SV.
Overriding/overloading a method with the same signature can be the same as defining a virtual method. The term method overloading usually applies to methods with a different signature (i.e. different types or numbers of arguments).
I agree with Dave. Function overloading normally refers to the case where you have the same function name with different signatures.
A simple example in C++;
class C {
virtual void print(int x);
virtual void print(float y);
}
Note the same function “print” has two different signatures. This is a very useful feature. However this is not supported in
SystemVerilog as far as I know. Not sure if there are plans in the committee to support this in the future.
@Dave, I understand the method/function overriding in System verilog. I was looking for the scenario like Logie explained, where we have the two methods with same name but different signatures in SystemVerilog. So it is not supported for sure in systemverilog.
“We have method overriding in system verilog, where the method in derived class can override the base class’s method. Both the methods should be of same name and same signature”
Quote: Both the methods should be of same name and same signature.
Actually, I mentioned the above thing continuing the context of method overriding.
Static methods can be overloaded, that means a class can have more than one static method of same name. But static methods cannot be overridden, even if you declare a same static method in derived class it has nothing to do with the same method of base class…Source
static function uvm_object_wrapper uvm_object::get_type ();
And in the function documentation, the example suggests:
class cmd extends uvm_object;
typedef uvm_object_registry #(cmd) type_id;
static function type_id get_type();
return type_id::get();
endfunction
endclass
In the example, the return type is type_id and it is different than uvm_object_wrapper, how is this overloading work even if we have two functions with the same name but different signatures?
Hi Tony,
I’m not sure if this example can be classified as overloading, because the type_id is a uvm_object_registry which, in turn, is derived from uvm_object_wrapper. So, because of that type_id is “accepted” as a uvm_object_wrapper as well.
But if there was no inheritance in this case, this example would not work in SystemVerilog.
Please let me take this opportunity to ask a more general OOP question, so.
Both covariance and overloading are types of polymorphism, right?
And in the following pseudo code example:
class animal;
class human extends animal;
animal animal_obj;
animal_obj = human.new();
Is it called covariance too? Or just polymorphism?