I thought I was familiar with template syntax until...
I'm reading "Modern C++ Design" and was comfortable with the code:
//Library Code
template <class CreationPolicy>
class WidgetManager : public CreationPolicy
{
...
};
//Application Code
typedef WidgetManager< OpNewCreator<Widget> > MyWidgetMgr;
Then expanding the example so the user of the template wouldn't have to specify <Widget> after "OpNewCreator" the code became:
//Library Code
template <template <class> class CreationPolicy>
class WidgetManager : public CreationPolicy<Widget>
{
...
};
//Application Code
typedef WidgetManager<OpNewCreator> MyWidgetMgr;
I don't understand how the Library Code here works. I assume its getting the Widget from its being derived from the templated class CreationPolicy<Widget>, but how that gets put into the above is beyond me. Can someone either provide a specific explanation of what this is doing, a general explanation that would encompass all such questions, or both? Thanks in advance, for even reading it over.
-ryan
I'm reading "Modern C++ Design" and was comfortable with the code:
//Library Code
template <class CreationPolicy>
class WidgetManager : public CreationPolicy
{
...
};
//Application Code
typedef WidgetManager< OpNewCreator<Widget> > MyWidgetMgr;
Then expanding the example so the user of the template wouldn't have to specify <Widget> after "OpNewCreator" the code became:
//Library Code
template <template <class> class CreationPolicy>
class WidgetManager : public CreationPolicy<Widget>
{
...
};
//Application Code
typedef WidgetManager<OpNewCreator> MyWidgetMgr;
I don't understand how the Library Code here works. I assume its getting the Widget from its being derived from the templated class CreationPolicy<Widget>, but how that gets put into the above is beyond me. Can someone either provide a specific explanation of what this is doing, a general explanation that would encompass all such questions, or both? Thanks in advance, for even reading it over.
-ryan