* Daniel Kay:
[long problem description]
The short of it seems to be: you need some notification when the client code's
derived class object is destroyed.
And one way to do that is to force the client code to use a special template
class as the most derived class.
Client code:
class MyObserverImpl: public Observer { ... };
typedef ConcreteObserver<MyObserverImpl> MyObserver;
where ConcreteObserver is a template class you provide, where the destructor
provides the notification you need.
You can force use of ConcreteObserver via the virtual base class with private
constructor and friend trick, described in the FAQ for the case of disallowing
further inheritance -- making a class "final" or "sealed" -- but I think
more useful for the case above, forcing a given most derived class.
One main problem with this technique is how to forward constructor arguments
from ConcreteObserver to, in the example above, MyObserverImpl. And one
solution is to require that every constructor except the default constructor
must have exactly one argument (which can be a struct), and then use a
templated constructor. There are also other solutions.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?