Given the following code:
void f()
{
class A
{
template <typename T>
void g() {}
};
}
g++ 4.4 (and also g++-4.6 -std=gnu++0x
) complains: "invalid declaration of member template in local class".
Apparently local classes are not allowed to have template members. What is the purpose of this limitation? Will it be removed in C++0x?
Note: If I make the local class itself a template, rather than giving it a template member:
void f()
{
template <typename T>
class A
{
void g() {}
};
}
I get "error: a template declaration cannot appear at block scope".
See Question&Answers more detail:os