Defining a new class

libAnyBus / Defining a new class

This tutorial describes how to define a class that can be used on the bus.

Consider the following class:

class C {
    int i;

    C ( int i ) : i ( i ) {};
};

This class must adhere to the following rules:

  • The class must be derived from anybus::Object

  • The class must have a default (no parameters) constructor (there is ways to get around this, but let's keep it simple).

  • The class must have a method called type that returns the class' corresponding anybus::Type object.

Consider the following:

class C : public anybus::Object {
    int i;

    C ( int i = 0 ) : i ( i ) {};
};

This satisfies the first two rules:

  • The class is now derived from anybus::Object,

  • and the constructor can be called without parameters.