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?
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