Parent parameter for new function in agent class

,

In reply to verif_learner:

Consider below function:

module test;
  function void message(string msg = "");
    $display("%s", msg);
  endfunction

  initial
  begin
    message("Started Simulation..");
    #10 $finish;
  end
endmodule

Here function message default argument is null. But when calling the function, we do provide an argument. So, when you want Agent instance to be part of Env, you need to provide parent argument when calling the function. By the way, call create() method which calls new().

E.g.

class Env;

  //build_phase()
  ..
  myAgent = Agent::type_id::create("myAgent", this); //Here parent is this component (Env)
  ..
endclass