Well nearly dynamically! When working on the ATL COM framework I came across a piece of framework code which makes a template parameter as the base class of a class which looked quite useful to me.
Here is a demo…
[sourcecode language=’cpp’]template
{
public:
LRESULT WindowProc(UINT uMessage, WPARAM wParam, LPARAM lParam );
};
template
LRESULT SomeWnd
{
//… Do some additional processing here …
return BaseClass::WindowProc( uMessage, wParam, lParam );
}
class MyDialog : public SomeWnd
{
};
class MyFrame : public SomeWnd
{
};
class MyCustomWindow : public SomeWnd<> // Use default template param
{
};[/sourcecode]
Now you may ask why I needed this, well I had to write some code in the WindowProc of a window class, but the base differed from implementation to implementation, so I adapted this idea from the ATL COM framework.
Since WindowProc is found in all CWnd derived window classes and at the same time I also needed to call the correct the default base implementation too, so this helped.