Clone() method not working

I tried to use clone method to copy req-rsp but it seems to be failing. I tried to display rsp.data_in but prints '0 all time. req.data_in is getting correct values.

Can someone point out what I am missing.

Thanks


//driver class main_phase

task run_phase(uvm_phase phase);
 pkt_seq_item req;
 pkt_seq_item rsp;
  
  forever
    begin
      seq_item_port.get_next_item(req);
      
      if(!$cast(rsp, req.clone())) `uvm_fatal("my_driver", "failed to clone");
      rsp.set_id_info(req);

     `uvm_info(get_type_name(),$sformatf("rsp.data_in %d",rsp.data_in),UVM_LOW);

      @(posedge vif.clk);
      if(req.write)begin
        vif.data_in = req.data_in;
        vif.write = req.write;
      end
      
      repeat(5)@(posedge vif.clk);
      rsp.data_out = vif.data_out;
            
      seq_item_port.item_done(rsp);
      
    end
endtask: run_phase

In reply to UVM_SV_101:

clone/copy are methods defined in theseq_item class.
How does the definition of

class pkt_seq_item

look like?

In reply to chr_sue:

Thank you! I was under the assumption that `uvm_object_utils_begin … *end macros were only for copy, print, compare…

I did not have then defined earlier.

Now I can see the clone method working after defining the macros in seq_item class.

Thanks!