OiO.lk Blog templates How to create type T and value of type T template with default type T?
templates

How to create type T and value of type T template with default type T?


As question says. I’d like to create a template, e.g. of class, that takes in typename T and T val as parameters, in which I can specify default T type.

I tried this:

template <typename T = int, T V = 0>
class Example
{

};

Example<int, 1> a; // compiles
Example<int> a; // compiles
Example a; // compiles
Example<1> a; // Error: "expected type specifier"

but the one thing I would like to work does not.

How can I do this right?



You need to sign in to view this answers

Exit mobile version