Passing queue of structs by ref

I have a task that takes in a queue of structs as ref.
File1 has:

  1. struct defined
  2. queue of struct declared and initialized
  3. task definition

File2(which reads file 1)

  1. Has a struct and queue declaration (exactly the same as file1)
  2. calling the task method
//file1
 typedef struct {
                     string field_name;
                     int addr;
                     int value;
                  } s_cdt_info_t;
     
 typedef s_cdt_info_t creg_arr[$];
 creg_arr  sn_creg_arr;

  task get_creg_fields(string sw_type, ref creg_arr sn_creg_arr);

      case(sw_type)

         "A" : sbn_creg_arr = asn_sbn_cdt_struct_q;
         ..
         default ..;
      endcase
   endtask : get_creg_fields
//----------------------------------------------------------------------//
//FILE2
typedef struct {
                     string field_name;
                     int addr;
                     int value;
                  } base_cdt_info_t;

base_cdt_info_t  abn_cdt_struct_q[$];

//calling the task
file1.get_creg_fields("A", abn_cdt_struct_q);

Error#1: the formal and actual arguments don’t match

to resolve Error#1, I tried $cast(struct_file1, struct_file2)
but that failed too as some unclear verilog syntax err

Maybe I am wrong on many levels… but need some initial thoughts to begin with…

You have two unpacked struct declarations. It does not matter that they have the same field layout—they are not assignment compatible. And because at least one of the fields is a string type, you cannot do a bit-stream cast between them.

Unpacked structs variables are only assignment compatible if they share the same single typedef. You need to put the struct typedef in a common package and import the package in both places you use the struct.

See SystemVerilog Coding Guidelines: Package import versus `include - Verification Horizons

Also, I suggest using a function void instead of a task unless your routine needs to consume time. And use an output instead of a ref argument. See Passing arguments by reference

thanks for the info, Dave.
The common package is an option for me but wanted to have more knowledge about the failure which you gave me. And yes, I do have time consuming element and that’s why I am using task over func.