Callbacks
Verfasst: So Mär 28, 2010 9:53 pm
Hi,
wenn ich bspw. folgenden Aufbau habe:
Jetzt passiert in k3 irgendetwas wichtiges, worüber k1 gerne informiert sein würde, deswegen ruft es die Funktion callback() auf. Bloß wie mach ich das mit dem Callback am besten?
main.cpp
main.h
So wie oben, dass ich einfach einen Pointer von k1 übergebe; oder gibt es da bessere Lösungen?
Mfg.
hackmack
wenn ich bspw. folgenden Aufbau habe:
Code: Alles auswählen
class k3;
class k2
{
private:
k3 k3_obj;
};
class k1
{
private:
k2 k2_obj;
public:
void callback()
};
main.cpp
Code: Alles auswählen
#include <iostream>
#include "main.h"
using namespace std;
k3::k3(k1 *grand_parent)
{
this->k1_ptr = grand_parent;
this->irgendetwas_wichtiges();
}
void k3::irgendetwas_wichtiges()
{
this->k1_ptr->callback();
}
k2::k2(k1 *parent) : k3_obj(parent)
{
}
void k1::callback()
{
cout << "Callback wurde aufgerufen" << endl;
}
k1::k1() : k2_obj(this)
{
}
int main()
{
k1 temp;
return 0;
}
Code: Alles auswählen
class k1;
class k3
{
private:
k1 *k1_ptr;
public:
k3(k1 *grand_parent);
void irgendetwas_wichtiges();
};
class k2
{
private:
k3 k3_obj;
public:
k2(k1 *parent);
};
class k1
{
private:
k2 k2_obj;
public:
k1();
void callback();
};
Mfg.
hackmack