0

I am looking way to create same parameterized class where based on parameter methods for the class will behave differently. In C i would implement this by using pointer to function and during creation will assign this pointer to different function, so user call same API.

The only way i can find would be using class that extends from class which methods i can override, but this would require user create different class.

Can't find in SystemVerilog something like pointer to function:

void (*foo)(int);

1 Answer 1

0

You are correct in your thinking there are no pointers to functions in SystemVerilog and that you would have to wrap your functions in a class. This is known as the Command Design Pattern or functor, and is a routine practice. The UVM's sequence body method is an example of this.

A simpler example is using an interface class to define the common API and ask that the user implement the function

interface class API #(type P1);
   pure virtual function int foo(P1 i);
endclass
class myAPI #(int P2) implements API#(.P1(int));
   function int foo(P1 i);
      return P2;
   endfunction
endclass
...
API#(int) fp; 
myAPI#(42) imp = new; 

fp = imp;
fp.foo(54);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.