1

I found some example of template in Modern C++ Design by A. Alexenderscu
where author used following lines

template
<
class T,
template <class> class CheckingPolicy  // <---- Please explain this line
>
class SmartPtr : public CheckingPolicy<T>
{
...
template
<
class T1,
template <class> class CP1,
>
SmartPtr(const SmartPtr<T1, CP1>& other)
    : pointee_(other.pointee_), CheckingPolicy<T>(other)
{ ... }
};

i do not understand meaning of in marked line. Please explain that line

Jai
  • 1,292
  • 4
  • 21
  • 41

1 Answers1

2

In this code example SmartPtr class template has one type parameter T and one template parameter CheckingPolicy. CheckingPolicy template template parameter itself has one type parameter: template <class> class CheckingPolicy. I recommend you to format template code which is unclear for you in the following way to make it more understandable:

template
    <
        class T, // type parameter of a SmartPtr class template
        template
            <
                class // type parameter of a template parameter CheckingPolicy
            >
        class CheckingPolicy // template parameter of a SmartPtr class template
    >
class SmartPtr // class template
Constructor
  • 7,273
  • 2
  • 24
  • 66
  • Simply put, the name of the template is ignored in `template` instead of `template`. Similar to functions `void foo(int)` instead of `void foo(int bar)` – balki Apr 16 '14 at 12:08
  • @balki Thank you for your valuable remark. But there are some cases in which it would not be ignored. – Constructor Apr 16 '14 at 12:11