------------------------------------------------------------------------------
MC logo
Compound Shape Implementation
[^] Code Examples
------------------------------------------------------------------------------
<<Compound Shape Class compound.cc Shape Driver I>>
#include "compound.h"

// Add a Shape to the list.
void CompoundShape::add(Shape *f) 
{
        if (numfig >= capacity || figs == NULL)
        {
                Shape **oldfigs = figs;
                capacity *= 2;
                figs = new Shape * [capacity];
                for(int m = 0; m < numfig; ++m)
                        figs[m] = oldfigs[m];
                delete [] oldfigs;
        }
        figs[numfig++] = f;
}

// Draw them all.
void CompoundShape::draw(Drawable &d)
{
        OffsetDrawable od(d, origx, origy);

        for(int n = 0; n < numfig; ++n)
                figs[n]->draw(od);
}
<<Compound Shape Class Shape Driver I>>