/** * testcomposite.cpp */ #include "composite.h" void main() { /** * Create the pieces. */ Component* trunk = new Composite(); Component* branch = new Composite(); Component* leaf1 = new Leaf(); Component* leaf2 = new Leaf(); /** * Assemble them. */ trunk -> add( branch ); branch -> add( leaf1 ); branch -> add( leaf2 ); /** * Start a cascade of operations. */ trunk -> operation(); /** * Clean-up. */ branch -> remove( leaf1 ); branch -> remove( leaf2 ); trunk -> remove( branch ); delete leaf1; delete leaf2; delete branch; delete trunk; }