Extended Parametrized class

Looking at section 8.25 Parametrized class in LRM, there is another way to override the base class parameter from extended class.

class D4 #(type P = C#(real)) extends P; // for default, T is real 
// I am assuming C#(real) overrides the base class Type.

I dont think that is happening in the below code.



typedef enum {ADD,SUB,MUL} opcode;

class A#(type T=int);
  T sub;
 
endclass


class B #(type Q = A#(real)) extends A;
  Q mux;
  
endclass



module tb;  

  B  #(real)a1;
  A base;
  
  
  initial begin
    a1 = new();
    base = new();
    a1.mux =10.23;
    base.sub = 10.45;
    $display ("Mux value in class B is %f",a1.mux);
    $display ("Sub value in class Base is %0.3f",(base.sub));
  end
  
  
  
endmodule


In reply to rag123:

It’s not clear what you are expecting. Your code is equivalent to

class B #(type Q = A#(real)) extends A#(int);
  Q mux; // equivalent to A#(real) mux;
 
endclass

In reply to dave_59:

Hi Dave,
I was expecting A Type to be have a value of real.

Example from LRM :
class D4 #(type P = C#(real)) extends P; // for default, T is real

I also found this text in one of your paper. Yin and Yan of OOP.

Parameters applied to
the extended class may propagate up to the base class.

In reply to rag123:

But you wrote

class B #(type Q = A#(real)) extends A;

The “extends A” is actually “extends A#()” which means “A with the default specialization”

If you wrote

class A#(type T);
  T sub;
endclass
class B #(type Q = A#(real)) extends A; // error

Then you would have gotten a compiler error because you did not provide an override for T in the second reference to A.