# Uvm\_component parent handle cannot be passed into static method inside virtual class

**URL:** <https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682>\
**Category:** UVM\
**Tags:** UVM, class, UVM\_OBJECT-and-UVM\_COMPONENT, class-handle, static-method, virtual\
**Created:** [April 6, 2016, 4:39pm UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682 "2016-04-06T16:39:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaino](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@Vaino](https://verificationacademy.com/forums/u/Vaino)\
**Post date:** [April 6, 2016, 4:39pm UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/1 "2016-04-06T16:39:59Z")

</div>

Hi all,

I am trying to create a generic method which could be utilized in the creation of any amount of any agent. Basically, my approach is to implement virtual parameterized class with static method targeted to create process. The problem is that it seems I can’t pass parent component handle to that implemented create method.

Here is an example case. Inside **example\_env** , I am trying to create six instances of **example\_agent**. m\_example\_agent is an dynamic array holding handles for those six occurrences of example\_agent. Parent uvm\_component handle is tried to pass to **support\_class** via **this** since uvm\_component’s create() method requires it.

```verilog

class example_env extends uvm_env;
  ...
  example_agent m_example_agent[];
  ...
  function virtual void build_phase(uvm_phase phase);
    ...
    m_example_agent = support_class#(example_agent, this)::create_child(6);
    ...
  endfunction: build_phase 
  ...
endclass: example_env

```

support\_class is declared as a virtual class and it has a static method called **create\_child** as follows:

```verilog

virtual class support_class #(type T = int, uvm_component parent);
  typedef T return_type_array[];

  static function return_type_array create_child(int number);
    string str;
    create_child = new[number];

    for (int i = 0; i < number; i++) begin
      create_child[i] = T::type_id::create({"agent_x", str.itoa(i)}, parent);
    end
  endfunction: create_child
endclass: support_class

```

Simulator doesn’t accept that but instead it says **“Class specialization parameter must be constant…”** once ::create\_child(6) is called. If I give a default value of **null** for parent parameter, it seems working.

Do I have any possibility to pass parent uvm\_component handle to my create\_child() method? Or do you have any other implementations in your mind? I wouldn’t like to throw this to the waste bin.

Sorry for the typos in the example code already in advance. Thanks for your help!

-Vaino

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [April 6, 2016, 5:06pm UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/2 "2016-04-06T17:06:07Z")

</div>

_In reply to [Vaino](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682):_  
Why do you want the parent to be a parameter of your class? Just pass it as the second argument to your create\_child class.

---

<div class="post-metadata">

**Author:** ![Vaino](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@Vaino](https://verificationacademy.com/forums/u/Vaino)\
**Post date:** [April 7, 2016, 6:23am UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/3 "2016-04-07T06:23:20Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/2):_

Actually, I don’t know. I just started to wonder why the heck I tried to pass parent handle via class parameterization. Thanks for your insightful comment.

But, I am still wondering whether it is good programming practice or not to set the size of the returned dynamic array by the new constructor inside the method such in my create\_child() function (create\_child = new[number])?

---

<div class="post-metadata">

**Author:** ![chr\_sue](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/chr_sue/32/1199_2.png) [@chr\_sue](https://verificationacademy.com/forums/u/chr_sue)\
**Post date:** [April 7, 2016, 6:38am UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/4 "2016-04-07T06:38:09Z")

</div>

_In reply to [Vaino](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/3):_

I’m wondering what your objective is with your implementation. Is there some theoretical interest or do you have a practical application. For a certain test the number of agents should be fixed or do you want to restructure your testbench when running a test?

---

<div class="post-metadata">

**Author:** ![Vaino](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/v/a4c791/32.png) [@Vaino](https://verificationacademy.com/forums/u/Vaino)\
**Post date:** [April 7, 2016, 8:04pm UTC](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/5 "2016-04-07T20:04:40Z")

</div>

_In reply to [chr\_sue](https://verificationacademy.com/forums/t/uvm-component-parent-handle-cannot-be-passed-into-static-method-inside-virtual-class/31682/4):_

I have a practical application behind that, but opening it in more detail isn’t relevant. But, based on my studies, the implementation works now fairly well. So, I think I have no more questions on that.
