I have the following test code
#include <iostream>
template <typename T>
struct PS
{
template <typename U>
static void foo()
{
std::cout<<"Some test code";
}
};
template <typename T>
void bar()
{
PS<T>::template foo<T>(); //won't compile without `::template`
}
int main()
{
bar<int>();
}
ISO C++03 14.2/4
: says
When the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.
The Standard talks about ->
and .
but not about ::
. Is it a defect in the C++03 Standard or am I missing something? Someone please enlighten me.
However the wording has been changed in N3126
When the name of a member template specialization appears after . or -> in a postfix-expression or after a nested-name-specifier in a qualified-id, and the object or pointer expression of the postfix-expression or the nested-name-specifier in the qualified-id depends on a template parameter (14.6.2) but does not refer to a member of the current instantiation (14.6.2.1), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.
Can someone give an example to illustrate what but does not refer to a member of the current instantiation
means in context of C++0x?
-PS