我正在 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 上运行它。