3

GCC doesn't seem to approve of instanciating templates with local classes:

template <typename T>
void f(T);

void g()
{
    struct s {};

    f(s()); // error: no matching function for call to 'f(g()::s)'
}

VC doesn't complain.

How should it be done?

uj2
  • 2,255
  • 2
  • 21
  • 32

1 Answers1

12

In C++03 it can't be done, C++0x will lift that restriction though.

C++03, ยง14.3.1/2:

A local type, a type with no linkage, an unnamed type or a type compounded from any of these types shall not be used as a template-argument for a template type-parameter.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236