Variation structure specification
I am defining a so called variable structure
template <class T, class... TRest>
struct Opa
{
Opa()
{
std::cout << "Mutiple-arguments template";
}
};
and want to specialize it for the case with 1 argument only like this
template <>
struct Opa<class T>
{
Opa()
{
std::cout << "One-argument template";
}
};
but the compiler just ignores this second structure and the output from
Opa<int> opa;
Opa<int, int> opa_opa;
- Mutiple-arguments template, Mutiple-arguments template
.
Specifying a template with one argument differently, for example
template <class T>
struct Opa
{...}
resulted in a compilation error. I realize my question is pretty simple, but googling didn't help. So please don't throw rotten tomatoes at me, and thanks for the answers.
Your syntax for a single argument specialization is incorrect. You are probably fully specialized in class T
on-site ad . You wanted this:
template <class T>
struct Opa<T>
{
Opa()
{
std::cout << "One-argument template";
}
};
Live example
Partial specializations are declared by listing the partial specialization parameters in angle brackets after template
(in your case, a parameter of the same type, class T
) and listing the arguments for the main template in angle brackets after the name of the main template (in your case, an argument of the same type, T
).