Example of Default Initializers in Templates


/************************************************************************
*

The following example shows a valid template declaration with default initializers:

*
************************************************************************/

// This example shows a template declaration
// with default initializers.

#include <stdio.h>

template <class T, int i=1> class X
{
public:
     T s;
     X(int j=4);
     int val(T&)
     {
       return i;
     };
};

template <class T, int i> X<T,i>::X(int j):s(i){
  printf("i=%d   j=%d\n",i,j);
}

void main()
{
  X<int>   myX(2);
  X<int,3> myX2(4);
}