How "ref" keyword used while passing class object as argument function

Hi ,

Could anyone explain, how the “ref” is useful/difference in following cases (case 1 and case 2)

class B;
int a;
int b;

endclass

class A;
int x ;
int y ;

function B fun ( B obj ); // case 1
function B fun ( ref B obj ); // case 2
// some code
return obj;
endfunction
endclass

module top;

A obj_a ;
B obj_b ;

initial
begin
obj_a = new();
obj_b = new();
obj_b = fun (obj_b);
end

endmodule

Thanks
Balu

In reply to kbkdec15:

The ref keyword is not needed because obj is already a class variable that has a handle that references a class object. You almost never need the ref keyword with function arguments except as an optimization when you have large aggregate data types as arguments. If you only need to access a few elements of an array, a ref argument saves you having to copy in or out all of the elements. \

For a task, you may want to read: const ref | Verification Academy

In reply to dave_59:

Thank you Dave.

I understood about the “ref” usage.

-Balu