mardi 24 janvier 2017

Calling functions implicitly from derived classes

In my main.cpp I have something similar to the following:

void OnEventStart(int id)
{
    // Do some stuff
}

This function is a callback, it is only triggered (by the main sdk that this is from) when an event has occured.

I now have this class:

class SomeClass {
public:
    void OnEventStart(int id);
};

void SomeClass::OnEventStart(int id)
{
    // Do some other stuff
}

Now I want to trigger void SomeClass::OnEventStart(int id) without doing something like this:

SomeClass class;
void OnEventStart(int id)
{
     // Do some stuff

     class.OnEventStart(id);

     // AnotherClass.OnEventStart(id);
     // Another.OnEventStart(id);
}

As you can imagine, using a method like this can easily clutter up the inital function/callback.

Aucun commentaire:

Enregistrer un commentaire