It is a common idiom in C++ to write a class whose sole data
member is a pointer to another class that provides the
implementation. Originally called "The Cheshire Cat Idiom" this
has more recently been dubbed "Compilation Firewall" and "The
Pimpl Idiom". This last comes from the following paradigm:

However, this is all by way on a preamble - since the
situation I want to address is motivated less by impementation
hiding and more by the desire to provide a variable
implementation. For example. we may want to vary between
implementations state1, state2 and state3 at run time. (A the
names suggest this is one reasonable way to implement state
machines.)

The only difficulty with this is that we can't write:

class state1 : public interface::impl {
...
};

because interface::impl is inaccessible.

There are two obvious approaches to resolving this
inacessibility isssue. Both of these are inelegant because
implementation details become exposed in the header file.

The first solution is to make impl a public member of
interface. Making impl public pollutes the client interface: