So, I am a bit rusty in C++ and so i might request something really stupid, however i don't find my answer anywhere and I am drained of your time.

I am making my very own icons using the Agar library. That isn't that important, but maybe it's. I register the icons by passing a function pointer for that Draw function. I wish to make use of the same for that two classes I've, simply because they share exactly the same BaseWidget class.

void Draw()
{
    BaseWidget* widget;

    //for each circle
    {
    widget->DrawCircle();
    }
}

I would like that, after i callDraw for my derived icons, it calls their specific DrawCircle function.

BaseWidget
{
public:
    virtual void DrawCircle();
}

WidgetA : BaseWidget
{
public:
    virtual void DrawCircle();
}

WidgetB : BaseWidget
{
// I want the BaseWidget DrawCircle to be called for this one.
}

This develops but crashes when Draw is known as. Basically not have the virtual key phrase for that function, it does not crash, but it is just the DrawCircle from theBaseWidget that's known as.

Any idea?

[Edit]

Real code:

typedef struct WorldWidget
{
// Some general stuff
    World* mp_world;

    void DrawCircle(Circle* ap_circle);

    void DrawWorld();
} WorldWidget;

typedef struct WorldViewerWidget : WorldWidget
{
//Specific stuff

    //void DrawCircle(Circle* ap_circle);

} WorldViewerWidget;

typedef struct WorldNavigatorWidget : WorldWidget
{
//Specific stuff

    //I don't want to redefine DrawCircle here.
} WorldNavigatorWidget;

I refactored a little since today, the main problem remains the same. Mainly:

void WorldWidget::DrawWorld()
{
std::map<int, Circle*>::iterator circleIterator = mp_world->GetFirstCircleIterator();
for(int i = 0; i < mp_world->GetCircleCount(); i++)
{
    DrawCircle(circleIterator->second);
            circleIterator++;
}
}

I did not even redefine DrawCircle in WorldViewerWidget yet. I construct it such as this, it really works. I put change WorldWidget with the addition of virtual to DrawCircle, also it crashes.

typedef struct WorldWidget
{
// Some general stuff
    World* mp_world;

    virtual void DrawCircle(Circle* ap_circle);

    void DrawWorld();
} WorldWidget;

Why?

Should you take away the keyword virtual, then your BaseWidget implementation will be known as when utilizing a BaseWidget pointer. Because it only crashes with virtual present, your WidgetA implementation of DrawCircle should be the issue.