Specializing a parameterized class by a parameter of it's containing class

In reply to orlevi:

The code you have written is not legal, you should have gotten a compiler error. The problem is there is no way in SystemVerilog to reference a generic parameterized class and later specialize it with a parameter override. As soon as you reference the generic class name A, it becomes a parameterized class with the default parameter values.

When you wrote

 B#(A,5) c1 = new();
 B#(A,8) c2 = new();

It is implicitly

 B#(A#(),5) c1 = new();
 B#(A#(),8) c2 = new();

And then the T in the class B expands to

A#()#(BB)   t1 = new(); 
 A#()#(BB+1) t2 = new();

It is very unfortunate the SystemVerilog chose to allow A to meanA#() instead of requiring the empty #().

If you need a workaround, I’ll have to know more about how you want to use the parameters.