1 Answer
  • 1
name Punditsdkoslkdosdkoskdo

Template default arguments

If I am allowed to do the following:

template <typename T = int>
class Foo{

Why am I not allowed to do the following in main?

Foo me;

But I must specify the following:

Foo<int> me;

C++11 introduced default template arguments and right now they are being elusive to my complete understanding.


You have to do:

Foo<> me;

The template arguments must be present but you can leave them empty.

Think of it like a function foo with a single default argument. The expression foowon't call it, but foo() will. The argument syntax must still be there. This is consistent with that.

  • 0
Reply Report