I found this question on a interview prep website. I think the reason a1 = b1 is not allowed is because derived class b uses different parameters but I don’t know how to solve it. Is $cast the way to go?
In the below example,"a1 = b1"is not allowed. Why is it not allowed and what is the solution ?
class a#(type T=int);
virtual function void func1();
$display("Inside base");
endfunction :func1
endclass
class b extends a#(real);
virtual function void func1();
$display("Inside derived");
endfunction :func1
endclass
module top;
a a1;
b b1=new();
initial begin
a1 = b1;
a1.func1();
end
endmodule:top