Add new function in base non virutal class

Dear Forum,

I have “axi_transaction” non-virtual class which does not have do_print function in it ( it is SystemVerilog based VIP).
So now I want to add do_print in it, please help to do it.
I extended from axi_transaction my own cstm_axi_transaction class and added do_print there.
However when I do $cast of the aXi_transaction object to its child cstm_axi_transaction it fails, and this failure is expected as the parent object does not contain child object data.
Any ideas how I can add do_print in “axi_transaction” class?
This is my code:

class cstm_axi_transaction extends axi_transaction;

function new (…)
endfunction

 function void do_print ();
…..
 endfunction

endclass


module Tb_top(  );
…
axi_transaction                               wr_transaction;
 cstm_axi_transaction                          cstm_wr_transaction;

initial
begin
  wr_transaction = mstr_agent.wr_driver.create_transaction("write transaction");
  
 $cast(cstm_wr_transaction,wr_transaction);  // -> $cast is failing here, as wr_driver.create_transaction returns axi_transaction type object
  cstm_wr_transaction.do_print();
  
  WR_TRANSACTION_FAIL_1b: assert(wr_transaction.randomize());
  
  cstm_wr_transaction.do_print();
  mstr_agent.wr_driver.send(wr_transaction);
end

Note: axi_transaction is not virtual class ,this is its proto:

class axi_transaction extends xil_sequence_item;

In reply to haykp:

You need to construct a cstm_axi_transaction object. Just extending the class is not enough.

In reply to dave_59:

Thanks for the answer
Even though I create a new object of cstm_axi_transaction object, still the $cast fails:

initial
begin
  cstm_wr_transaction = new ("cstm_write_trans");
  wr_transaction = mstr_agent.wr_driver.create_transaction("write transaction");
  $cast(cstm_wr_transaction,wr_transaction);
...

ERROR: $cast failed in File …

I think the reason is that wr_transaction does not contain extra function(e.g. do_print) defined in the cstm_wr_transaction class, as a result $cast cannot do casting.
Is my understanding right?

In reply to haykp:

Correct. You need a handle to a cstm_wr_transaction object (or one extended from that) to cast it to a cstm_wr_transaction class variable.