0

I saw the following code:

template<class T, T t = T()>
class A {
    t > T()
};

I am confused about the second template parameter( t = T() ). Is that a function returning T or a non-type parameter? And what does it mean by comparing t and T()?

roy.atlas
  • 411
  • 2
  • 8
  • 3
    Are you sure that's the exact code you saw? Because unless there's an obscure part of C++ I don't know about, `t > T()` is an expression that is invalid in that context. – Cornstalks Sep 10 '16 at 21:55
  • The full code locates [here](http://www.interqiew.com/ask?ta=tqcpp02&qn=2) – roy.atlas Sep 13 '16 at 02:49

1 Answers1

2

The second argument is a non-type parameter but it is not a function.

T t = T()

simply specifies a default value of the template parameter t.

You can create instances of the template using:

A<int> a1;  // Equivalent to A<int, 0>
A<int, 10> a2;

A<bool> a3;  // Equivalent to A<bool, false>
A<bool, true> a4;

The line

t > T()

does not make sense at all.

R Sahu
  • 204,454
  • 14
  • 159
  • 270