I have been working through Microsoft's "Learn to Program for Windows in C++" articles found here
Learn to Program for Windows in C++
http://msdn.microsoft.com/en-us/library/windows/desktop/ff381399%28v=vs.85%29.aspx
and have a question about the end of module 1: http://msdn.microsoft.com/en-us/library/windows/desktop/ff381400%28v=vs.85%29.aspx
In their sample they derive a window from a base class, where the base class is as follows:
template <class DERIVED_TYPE>
class BaseWindow
{
public:
static LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DERIVED_TYPE *pThis = NULL;
...etc
I am just trying to understand why this is created as a template. My understanding of class templates is to allow us to write a class, and use that class for any data type we want. Eg MyVector<int> or MyVector<double>
In this case I cant understand why they have used a template class. Can they just have gone
class MainWindow : public BaseWindow
Instead they have used
class MainWindow : public BaseWindow<MainWindow>
I just cant understand what other kinds of windows can be "derived" from this base case? I can understand in the case of calling a function with an int or a float, and needing a template there, but not in this case.
Thanks for your time