0
class parent;
int a = 10;
endclass

class child extends parent;
int b = 10;
endclass

module main;
  parent P;
  child C;

  P = new();
  C = new();

  initial begin
    $display("a=%d\n",C.a);
  end
endmodule

I tried to run this code using Synopsys VCS. It is giving an error at the object creation after the handle declaration. The error is as follows:

Error-[SE] Syntax error Following verilog source has syntax error : "class.sv", 20: token is '=' P = new();

4
  • The output does not match the code you show. What are you expecting? Commented Mar 28, 2018 at 5:15
  • Your edits completely changed the sense of the question so that the answer is no longer an answer to the question and will make no sense to future readers. So, I have rolled them back. If you have another question, please ask it as another question. I have also deleted all the extraneous output from VCS. Commented Mar 28, 2018 at 8:09
  • Hi Matthew! All I am expecting is to create a object using the the class handle. If you run the above code it gives error but if you do parent P = new() Then it does not give any error. I want to know the reason behind this. Commented Mar 28, 2018 at 8:19
  • Hi @K.Piyush, then ask a new question and I will answer it. The idea behind Stack Overflow is that your questions and answers become useful to future Googlers. Conversations like this and edits that completely change the sense of a question are not useful to future Googlers. Commented Mar 28, 2018 at 8:27

1 Answer 1

1

Put your constructors inside the initial block.

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.