I have found it very handy to be able to parameterize an interface, but I have made a change to my class structure (added some hierarchy), where I now need the ability to parameterize a task that is defined in an interface. I have done a lot of google searches on this topic, and even tried to do it, but I always get compile or elaboration errors. I suspect the answer is that it is not possible to parameterize a function or task, but that the parameterization must be declared in the interface or class definition. Is that correct?
Here is a simplified example of what I would like to do:
// begin code (fails to compile)
interface tester // #(type T) // removed type parameter at the interface definition
// trying to reuse code that can output 3 different types of leaf classes
task automatic compare #(type T) (input base_class bc, ref T leaf_class_inst);
// implementation
endtask
endinterface
// end code
// begin hacked work around (compiles)
interface tester #(type T)
task automatic compare(input base_class bc, ref T leaf_class_inst);
endtask
endinterface
tester i1;
base_class comp;
initial begin
comp = new();
end
initial begin
automatic leaf_class t1 = new();
automatic leaf_class t2 = new();
automatic base_class b1 = t1;
automatic base_class b2 = t2;
i1.compare(comp, b1);
i1.compare(comp, b2);
//i1.compare(comp, t1);// elaboration error
//i1.compare(comp, t2);// elaboration error
end
// end hacked work around