Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Class having object of itself

Status
Not open for further replies.

jdshah

Junior Member level 3
Joined
Dec 17, 2010
Messages
28
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Ahmedabad
Activity points
1,481
In below code a class is having object of itself. Object of own type is created before class definition completes (before endclass.)
This is working. Compiler do not give any error. Can anyone explain me how this works?

Code:
class test;
  test self;
  function create_me();
    self = new();
    self.display("self");
  endfunction
  function display(string s = "this");
    $display("from function display %s",s);
  endfunction
endclass
 
module test_module();
  test test_ob;
  initial
    begin
      test_ob = new();
      test_ob.create_me();
      test_ob.display();
    end 
endmodule

Output :
from function display self
from function display this
 

This is because the Verilog/SV compile has several stages. So after the first passes, it knows what a test class is, so you can create one. It's on a further pass that it accesses all the member functions.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top