相关疑难解决方法(0)

g ++/Clang中的另一个错误?[C++模板很有趣]

查看以下代码(仅为了好玩而编写)

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)

c++ templates

31
推荐指数
1
解决办法
3442
查看次数

标签 统计

c++ ×1

templates ×1