#include <stdio.h>

template <class Z>
class Foo {                             /* the general version */
    Z value;
public:
    Foo(Z v) : value(v) {}
    Z Get() const { return value; }
    const char *Which() const { return "general"; }
};

template <class T>
class Foo<T*> {                         /* for any pointer type */
    T *ptr;
public:
    Foo(T *p) : ptr(p) {}
    T Get() const { return *ptr; }      /* T is what it points to */
    const char *Which() const { return "for pointers"; }
    unsigned long TargetSize() const { return sizeof(T); }
};

int main()
{
    int n = 5;
    double d = 2.5;
    int *pn = &n;
    Foo<int> a(n);
    Foo<int*> b(&n);
    Foo<double*> c(&d);
    Foo<int**> e(&pn);
    printf("Foo<int>:     %-13s Get() = %d\n", a.Which(), a.Get());
    printf("Foo<int*>:    %-13s Get() = %d, T is %lu bytes\n",
           b.Which(), b.Get(), b.TargetSize());
    printf("Foo<double*>: %-13s Get() = %g, T is %lu bytes\n",
           c.Which(), c.Get(), c.TargetSize());
    printf("Foo<int**>:   %-13s *Get() = %d, T is %lu bytes\n",
           e.Which(), *e.Get(), e.TargetSize());
    return 0;
}
