Parameterized class: specialization

In reply to NiLu:

It won’t apply to you, because I was calling some DPI imported functions (in the places you’re calling get_next_real/complex) and I changed it to use VPI system tasks, which aren’t strongly typed.

I guess in your case, using a number base class does make the most sense. You’d just call something like get_next_number(x) and the compiler shouldn’t have any problems. x would still typed by the parameter. This way you combine polymorphism with templates.

class number;
  // API that defines what a number can do
endclass

class real extends number;
  // extra stuff for a real
endclass

class complex extends number;
  // extra stuff for a complex
endclass

Like you said, whether it makes sense to keep the parameterized class in this case, I’m not sure. It would probably strongly depend on your use case.