How to use local classes with templates?

GCC does not seem to approve instantiation 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 is not complaining.

How to do it?

+3
source share
1 answer

In C ++ 03, this cannot be done; C ++ 0x will raise this limitation.

C ++ 03, Β§14.3.1 / 2:

A local type, a type without a binding, an unnamed type, or a type made up of any of these types should not be used as a template argument for a template type parameter.

+12
source

Source: https://habr.com/ru/post/1753000/


All Articles