Classes

Classes can be declared the following way:

  class name
  {
    method1(...) {}
    ...
  };

Inside the class, method functions are declared without the 'static' keyword. The method with the name of the class is the class constructor. For example:

  class myclass
  {
     myclass(x,y)
     {
       print("myclass constructor has been called with two arguments: ", x, y);
       this.x = x;
       this.y = x;
     }
     ~myclass()
     {
       print("destructor has been called: ", this);
     }
  };

Inside the class methods, the 'this' variable can be used to refer to the current object.

Only one constructor per class is allowed.

Class instances are created like this:

And object attributes (or fields) are accessed like this:

A new attribute is created upon assigning to it:

Accessing an unexisting attribute generates an exception, which can be caught.

The following special method names exist:

Simple class inheritance is support. Derived classed are declared like this:

Here we declare the 'derived' class that is derived from the 'base' class. For derived classes, the base class constructor can be called explicitly:

If the base class constructor is not called explicitly, IDA will call it implicitly, without any arguments.

It is possible to call base class methods using full names:

The 'this' argument must be passed explicitly in this case.

When there are no more references to an object, it is automatically destroyed. We use a simple reference count algorithm to track the object use. Circularly dependent objects are not detected: they are never destroyed.

The following built-in object classes exist:

Human readable form of the typeinfo can be obtained by calling the print() method. The type size can be calculated using the size() method.

Last updated

Was this helpful?