|
-
//main.cpp
#include "Shapes.h"
void push_shape( Shape* ps, int& cnt, Shape* shapes[] );
int main()
{
// Array of pointers to shapes:
Shape* shapes[ 100 ] = { 0 };
int shape_cnt = 0;
push_shape( new Circle(10), shape_cnt, shapes );
push_shape( new Square(5), shape_cnt, shapes );
for ( int idx = 0; idx < shape_cnt; ++idx ) {
// Call virtual function:
shapes[ idx ]->draw();
}
}
void push_shape( Shape* ps, int& cnt, Shape* shapes[] )
{
shapes[ cnt++ ] = ps;
}
|