查看以下代码(仅为了好玩而编写)
namespace N
{
template<typename T>
struct K
{
};
}
template<typename T>
struct X
{
typename T::template K<T> *p; //should give error
//N::K<int> has no template member named `K`
};
int main()
{
X<N::K<int> > l;
}
Run Code Online (Sandbox Code Playgroud)
代码在g ++(4.5.1)和Clang上编译,而Comeau和Intel C++给出(类似)错误.
我在Comeau上遇到的错误是:
"ComeauTest.c", line 13: error: class "N::K<int>" has no member "K"
typename T::template K<T> *p;
^
detected during instantiation of class "X<T> [with T=N::K<int>]" at
line 18
"ComeauTest.c", line 13: error: expected an identifier
typename T::template K<T> *p;
^ …Run Code Online (Sandbox Code Playgroud)