Nested templates require the usage of template
keyword, as explained in this answer. Here's a concise demonstration that results in a compiler error:
template <int T>
struct A {
template <int U>
static void b(int x) {
}
};
template <int T>
void test() {
A<T>::b<T>(T); // Should be:
// A<T>::template b<T>(T);
}
int main() {
test<0>();
}
As a challenge, I was trying to think of a program where two possibilities (with or without template
) are both valid but have two different meanings, but I couldn't wrap my head around the operator overloading business. Is it possible to make A<T>::b<T>(T);
a valid statement?