1
template <int parameter> class MyClass

is the above a template specialization? I don't think so but I'm unsure of it, I didn't know templates could receive arguments as functions.. where do their arguments get stored?

Johnny Pauling
  • 12,701
  • 18
  • 65
  • 108

2 Answers2

3

Template parameters do not necessarily need to be type names: they can be numbers as well. For example, std::array takes a parameter of type size_t for the array size.

In your case, the class template takes a parameter of type int, which is entirely OK. Here is an example of how you can use such a parameter:

template <int param> struct MyClass {
    int array[param]; // param is a compile-time constant.
};
int main() {
    MyClass<5> m;
    m.array[3] = 8; // indexes 0..4 are allowed.
    return 0;
}
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
1

Their arguments are stored within their type information.

No, that is not a template specialization. Have a look at this:

template <int, int> class MyClass;         // <-- primary template
template <int>      class MyClass<int, 4>; // <-- partial specialization
template <>         class MyClass<5, 4>;   // <-- specialization
Sebastian Mach
  • 38,570
  • 8
  • 95
  • 130