Interface class as function argument (with ref)

Hello!
Could anyone help me with such a question:

Is it possible to use interface classes as function arguments with ref direction?

My example (just code snippet):


//DECLARATIONS
---------------------------------------------------------
typedef logic [7:0] my_type;
interface class _word#(type symbol_type);

    pure virtual function int size();
    pure virtual function symbol_type get_symbol(int i);
endclass
---------------------------------------------------------
interface class my_word extends _word#(my_type);
endclass
---------------------------------------------------------
class testword implements my_word;
 typedef logic [7:0] custom_my_type;
 custom_symbol_t q[$];
virtual function int size();
     return $size(q);
    endfunction
virtual function custom_symbol_t get_symbol(int i);
        return q[i];
    endfunction
    function new(int n);
        for(int i=0;i<n;i++)
        begin
        q.push_back(0);
        end
        endfunction
endclass
class my_User;
function void use_interface(ref my_word word);
$display("word size=%0d",word.size());
endclass

//USAGE
program runtest();
initial
begin
    testword _word =new(9);
    my_User user;
    user.use_interface(_word);

end
endprogram

If I delete “ref” in use_interface, everything works fine. But with ref I have an error in questasim 10.5c
(when trying to run simulation, compilation is ok):Actual argument expression for ref formal ‘word’ is not an equivalent type.

Thanks!

In reply to avek:

ref arguments require equivalent types between the formal and actual arguments types. formal type ‘word’ is of type my_word, and actual is of type testword.

There is no need to use a ref argument here. Please see const ref | Verification Academy

In reply to dave_59:

In reply to avek:
ref arguments require equivalent types between the formal and actual arguments types. formal type ‘word’ is of type my_word, and actual is of type testword.
There is no need to use a ref argument here. Please see Const ref - SystemVerilog - Verification Academy

Thank you for fast reply!
Maybe it was a bad example by me, and when using functions for printing, there is of cause no need to use a ref argument. But if i want to change structures that i send to ‘my_user’ - for example elements of queue. If I don’t use ‘ref’, such elements would be changed only inside ‘my_user’ because of copying by value.

I have found the solution:

To use declaration of the interface class,and send it to ‘my_user’ instead of ‘testword’ object, such as:


my_word word_pointer;
word_pointer=_word;
user.use_interface(word_pointer); 

But maybe there is better solution, and you’ll point me on it.
Thank you in advance!

In reply to avek:

What you did works, but is an extra step. When you pass a class handle by value, you are only coping the value of the handle, not the object. Once you have a handle to an object, you can modify any of its members from within the function.

In reply to dave_59:

Thanks a lot, Dave!
I’m really sorry for asking such questions, I just have not read language reference and your
previous answer properly.