Can i store child class to uvm_config_db using parent class type

Hi All,

I have a question on uvm_config_db.
Let’s say I have two classes, class animal and class cat which is a child class of class animal. I wonder if I can store a cat object to uvm_config_db with the type animal?

Example code:

class animal extends uvm_object;
  int age;
endclass

class cat extend animal;
  string breed;
endclass

class sample_test extends uvm_test;
  cat c_test;
  sample_env env;
  ...
  function build_phase (uvm_phase phase);
    create the object env and c_test
    c_test.breed="russian_blue";
    uvm_config_db#(animal)::set(this,env,"animal",c_test);
    ...
  endfunction
  ...
endclass

class sample_env extends uvm_env;
  cat c_env;
  string breed;
  ...
  function build_phase(uvm_phase phase);
    uvm_config_db#(animal)::get(this,"","animal",c_env);
    breed=c_env.breed;
   endfunction
endclass

I wonder for the above code, can env.breed successfully got the value of “russian_blue”(c_test.breed)?

Thanks in advance!

Hao

In reply to peterjin:

Did you try it?

Please see my article that discusses casting.

In reply to dave_59:

Hi Dave,

Thanks for pointing me to the article, now I understand it.

Thanks,

Hao