A constructor is simply a method to create a new object of a particular class data-type.
C/C++ requires complex memory allocation techniques and improper de-allocation could lead to memory leaks and other behavioral issues. System Verilog, although not a programming language, is capable of simple construction of objects and automatic garbage collection.
class Packet;bit[31:0] addr;functionnew();
addr =32'hfade_cafe;endfunctionendclassmodule tb;initialbegin
Packet pkt =new;// Calls the new() function which sets addr to 'hfade_cafe
$display ("addr=0x%0h", pkt.addr);endendmodule
ncsim: *W,RNQUIE: Simulation is complete.