0

Would you let me know why do we have to have the "new" keyword in twice in systemverilog? ​

 class MyClass;
   int number; 
   function new(); 
     number = 0; 
   endfunction
 endclass

 module test;
   MyClass test1 = new();
 endmodule

As you can see, there are used in twice "new" keyword.

Could you let me know why do we need to use in twice?

1 Answer 1

1
function new();
    number = 0; 
endfunction 

provides implementation of the function new(). When we call:

MyClass test1 = new();

we are creating test1. In order to create it, we call function new(), whose implementation we defined above. When we call new() it will ensure that property number of test1 is initialized to 0 (because that is what is happening inside of new()).

I hope my explanation is clear.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.