Callbacks in C++


manual polymorphism

problem:

You want to pass a class around by value, but at the same time the class needs polymorphic behavior.

context:

forces:

solution:

The solution given is for the single polymorphic member function case.

forces resolved:

design rationale:

While the Handle/Body pattern and Counted Body pattern [Coplien94] [Coplien92] can be used, those solutions still require heap allocation to occur, those techniques simply reduce how often heap allocation must be performed. For classes that are sufficiently simple, it is better to avoid heap allocation completely.

This technique is best for when creating a family of classes that are an abstract data type and should have behavior and functionality similar to a built in type.

[View/Add Comments]


Callbacks in C++
Copyright © 1996-2000 Paul Jakubik
Created: 26 July 1996. Last update: 26 November 2000.
pauljakubik@yahoo.com