zhon1231 Posted November 29, 2011 Report Share Posted November 29, 2011 Hi all, I am in the middle of writing a parametrized class, and I hit a road block. Is there a way I can overwrite a parameter in the type_id::create call? For example, can I do something similar to this? Class A #(int j=10) .... endclass Class B A m_a; function void build(); case(mode) 0: m_a = A#(7)::type_id::create(...); 1: m_a = A#(2)::type_id::create(...); 2: m_a = A#(11)::type_id::create(...); default: m_a = A#(4)::type_id::create(...); endcase endfunction endclass Any comment is greatly appreciated! Thanks, Billy endclass Quote Link to comment Share on other sites More sharing options...
dave_59 Posted November 29, 2011 Report Share Posted November 29, 2011 (edited) You would need to have A extended from a common base class so that m_a could be assigned with any specialization of A. As you have written it A m_a; // is the same as A #() m_a; // which is the same as A #(10) m_a; It would be better to write virtual class A_base; pure virtual methods... endclass class A #(int j) extends A_base; endclass A_base m_a;and your build method would be the same.You should be careful about what you choose to parametrize in a class. Take a look at the DVCon paper I reference at the bottom of my blog article on parameters. BTW, writing class A #(int j) without a default assignment means that you are required to have A #(something) when you reference it. Then A obj_h; would be illegal Edited November 29, 2011 by dave_59 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.