SystemVerilog Datatype: Class (Part 1)

Previous: Introduction to Classes | Next: Properties and Methods

Object Instance and Object Handle

The definition of the class Triangle is a good starting point for us. However, the definition by itself is not that useful, until we create an instanceof the class by a variable declaration.

   Triangle t;

Here, t is called an object handle of class Triangle. Note that, even though it is defined, t is still uninitialized. By SystemVerilog rule, all uninitialized object handles have a special value of null. So, it is possible to check if an object handle is initialized, just by checking if its value is null.

   if (t == null)
      ... // do proper initialization

A customary way of doing proper initialization is to use the new() function defined in the class.

   if (t == null)
      t = new;

Or, otherwise, in the declaration itself:

   Triangle t = new;

At this point, we say that t is an object handle to an object of class Triangle.

We will talk more about the function new() next time, but it is easy to see that an object handle is safer to use only after proper initialization.

Previous: Introduction to Classes | Next: Properties and Methods Share/Save/Bookmark




Verification Management
Join Verification Management Group


Shop Amazon - Contract Cell Phones & Service Plans

Book of the Month