From instruction: Draw a straight line and follow it
Code: framework by 0rel
a polymorphic line
#define STRAIGHT 0 class Thing { public: Thing( int a ) : attribute( a ) {} virtual bool draw() = 0; virtual Thing * follow() = 0; protected: int attribute; }; class Line : public Thing { public: Line( int a ) : Thing( a ) {} virtual bool draw() { // todo return true; } virtual Thing * follow() { // todo return this; } }; int main() { Thing *it = new Line( STRAIGHT ) ; while( it && it->draw() ) { it = it->follow(); } if( it ) delete it; return 0; }
[download]
Written in C++.