1

我正在 Windows 上使用 g++ 3.4.4 版编译此代码:-

#include <iostream>

template< int i >
class LOOP{
 public:
    static inline void EXEC(int* count){
        (*count)++;
            LOOP< i-1 >::EXEC(count);
   }
};

template<> class LOOP< 0 >{
  public:
    static inline void EXEC(int* count){
   (*count)++;
   }
};

 int main(int i){

int barely = 0;
LOOP< 1000 >::EXEC(&barely);
 }

它抱怨,嵌套名称说明符中使用的类型 LOOP<500> 不完整,并且在它之前有一个先前实例化的列表,“从静态 void LOOP::EXEC(int *) 实例化 i - 1000”等等。

当我将其更改为 LOOP<100> 时,它编译得很好。

编辑如果这会影响实现限制,我将在 cygwin 上运行它。

4

1 回答 1

1

您达到了实现的模板深度限制。-ftemplate-depth=1005您可以通过使用(modern GCC) 或-ftemplate-depth-1005(older GCC)编译来增加限制。

于 2012-05-24T13:02:58.513 回答