Jump to content

Parameterized Clases

Recommended Posts

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)



Class B

A m_a;

function void build();


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(...);




Any comment is greatly appreciated!




Link to comment
Share on other sites

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...
class A #(int j) extends A_base;

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 by dave_59
Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...