Skip to content

Class Definition

Davis Brown edited this page Aug 28, 2018 · 6 revisions

Classes in SQF++ are typically defined within their own containing file. They will need to #include any class files on which they inherit from.


Definition

Classes are defined in a basic layout. In the following Example, class ObjectWrapper is defined, containing a variable containedObject and given a method isNull which checks if the contained object is null.

class ObjectWrapper {
    var containedObject = objnull();

    function constructor(Object _toWrap) {
        containedObject = _toWrap;
    }

    function copy_constructor(Class _objectWrapper) {
        containedObject = _objectWrapper.containedObject;
    };

    function destructor() {
        deleteVehicle(containedObject);
    }

    function isNull() {
        return isnull(containedObject);
    }
}

Constructor and Destructor methods take on the forms of functions named constructor and destructor respectively. A copy constructor may be specified by a function named copy_constructor, it must take a Class parameter which holds the object being copied

Inheritance

Classes can also inherit from an arbitrary number of parent classes

Class A { ... }
Class B { ... }
Class C : A , B { ... }
Clone this wiki locally