class R {public: R() { next = 0; } virtual ~R() { if (next) delete next; } void insert(A& r); void process() { action(); if (next) (*next)->process(); } virtual void action() = 0; protected: A* next; }; R::insert(A& r) {
R needs some} trickery
if (!next) next = &r; else (*next)->insert(r); }