Reputation: 5
I'm trying to write a function that accepts an argument that is a const object handle.
function void example(const MyClass ob);
//--
endfunction
When i try to run this code I get an error:
syntax error, unexpected type name. The type 'MyClass' is defined at test.sv(1).
You can make a const object handle, but why you cannot do it in a function argument list? By the way - I'm aware that this only be a const object handle, not const class object and it it's (unfortunately) immposible to make const class object in SystemVerilog.
Upvotes: 0
Views: 882
Reputation: 42748
There is no such thing as a const object handle. There are const class variables. Like any const variable, they get assigned a value once as part their declaration, and become read-only after that.
A class variable has a value which is the handle to a class object. You want to be able to copy a function argument with the handle that got passed in as an input to the function. If SystemVerilog allowed you to declare an argument as a const variable, you could not make an assignment to it.
There is the concept of const ref
function argument, but that has very little value as that only prevents modification of the local argument variable. You can still write to any class member given a handle to the object.
Upvotes: 2