Originally Posted by
Elysia
This can be avoided with template, as shown below:
The method you and Laserlight are talking about is definitely a good one, but it still, in theory, allows the possibility for the callback driver to poke around inside the T object when it shouldn't. In practice, this would be extremely difficult because you don't know what's in there, but a void * completely guarantees that the code won't touch it, since it has no idea what type it is (even as a template parameter).
Normally though, I'd define a callback API like this:
Code:
class Callback
{
public:
virtual ~Callback() {}
virtual void DoIt() = 0;
};
void DriveTheCallback(Callback *cb)
{
cb->DoIt();
}
The actual callback just inherits from Callback and overrides DoIt().