Got an Error while using set_type_override_by_type

Hi All,
While using the type overriding I got an error. Issue is the "newly added analysis port is not a class item ". Please help me to resolve the Issue.

The code as follows:

//Base monitor
  class base_monitor extends uvm_monitor;
 
   `uvm_component_utils(base_monitor)
   
   //declaration of variables and analysis ports

   function new(string name,uvm_component parent);
     super.new(name,parent);
   endfunction : new

   virtual function void build_phase(uvm_phase phase);
     super.build_phase(phase);  
   endfunction : build_phase

   virtual function void connect_phase(uvm_phase phase);
    //connections
   endfunction : connect_phase

   task run_phase(uvm_phase phase);
      //code                         	  
   endtask : run_phase

endclass : base_monitor

// extended monitor
class ext_monitor extends base_monitor;
 
   `uvm_component_utils(ext_monitor)
   
   //new analysis port declared
   uvm_analysis_port #(seq_item) pkt_port;
   function new(string name,uvm_component parent);
     super.new(name,parent);
     pkt_port = new("pkt_port", this);
   endfunction : new

   virtual function void build_phase(uvm_phase phase);

     super.build_phase(phase);
     
   endfunction : build_phase

endclass : ext_monitor

class base_agent extends uvm_agent;

	uvm_active_passive_enum is_active = UVM_ACTIVE;

	`uvm_component_utils(base_agent)

	base_driver driver;
	base_sequencer sequencer;
	base_monitor monitor;

	function new(string name,uvm_component parent);
		super.new(name,parent);
	endfunction

	virtual function void build_phase(uvm_phase phase);
	   super.build_phase(phase);
           if(is_active == UVM_ACTIVE) begin
              driver = base_driver::type_id::create("driver",this);
              sequencer = base_sequencer::type_id::create("sequencer",this);
           end
           monitor = base_monitor::type_id::create("monitor",this);
	endfunction : build_phase

	virtual function void connect_phase(uvm_phase phase);
           if(is_active == UVM_ACTIVE) begin
              driver.seq_item_port.connect(sequencer.seq_item_export);
           end

        endfunction

endclass : base_agent

class ext_agent extends base_agent;
  `uvm_component_utils(ext_agent)

  function new (string name = "ext_agent", uvm_component parent = null);
    super.new(name, parent);
  endfunction : new

  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);
  endfunction : build_phase

endclass : ext_agent


class module_env extends uvm_env;
  `uvm_component_utils(module_env)

  ext_agent active_agent;
  ext_agent passive_agent;

  function new(string name = "module_env", uvm_component parent = null);
    super.new(name, parent);
  endfunction : new

  virtual function void build_phase(uvm_phase phase);          
    super.build_phase(phase);
    
    uvm_config_int::set(this,"active_agent","is_active",UVM_ACTIVE);
    uvm_config_int::set(this,"passive_agent","is_active",UVM_PASSIVE);

    active_agent  = ext_agent::type_id::create("active_agent", this);
    passive_agent = ext_agent::type_id::create("passive_agent", this);    

  endfunction : build_phase

  virtual function void connect_phase(uvm_phase phase);
    super.connect_phase(phase);
  endfunction : connect_phase

  function void end_of_elaboration_phase(uvm_phase phase);
    super.end_of_elaboration_phase(phase);
  endfunction : end_of_elaboration_phase

endclass : module_env

class top_env extends uvm_env;
 `uvm_component_utils(top_env)
 module_env env;
 scoreboard scbd;

 function new(string name, uvm_component parent);
   super.new(name,parent);
 endfunction

 function void build_phase(uvm_phase phase);
   // Overriding 
   set_type_override_by_type(base_monitor::get_type(),ext_monitor::get_type());
   super.build_phase(phase);
   env = module_env::type_id::create("env",this);
   scbd = scoreboard::type_id::create("scbd",this);
 endfunction : build_phase

 function void connect_phase(uvm_phase phase);
   super.connect_phase(phase);
   env.active_agent.monitor.pkt_port.connect(scbd.pkt_import); // I am getting the Issue: "pkt_port is not a class item"
 endfunction : connect_phase

endclass : top_env

Thank you

In reply to Kanth:

All of the connections made need to refer to the base classes. In this case, it would be ‘base_monitor’. Since pkt_port only exists in the extended ‘ext_monitor’, the connect phase has no knowledge of this port, hence the error.

Typically, extended classes will only change the behavior of an object or component, either by an added constraint or additional checks. You won’t be able to add any additional exports/imports as the base class has no access to these.

In reply to cgales:

Thank you Mr.cgales