The code is pretty straigh-forward. The code works if there isn't IDumb
and I pass dumbClass
directly to dumbWin
. But when dumbClass has IDumb interface, the code crashes at print()
.
using namespace std;
class IDumb {
public :
virtual void print() = 0;
};
class dumbClass : public IDumb {
public :
void print() {
cout << "this is dumb class" << endl;
}
};
class dumbWin : public Fl_Window {
IDumb *dc;
public:
dumbWin(IDumb *dc) : Fl_Window(100, 100, "win") {
Fl_Button *b = new Fl_Button(10, 10, 50, 25, "OK");
b->callback((Fl_Callback*)callbk, this);
end();
this->dc = dc;
}
void print() {
dc->print();
}
static void callbk(void *p) {
cout << "OK" << endl;
((dumbWin*)p)->print();
}
};
int main(int argc, char **argv)
{
IDumb *dC = new dumbClass();
dumbWin *dW = new dumbWin(dC);
dW->show();
return Fl::run();
}