我在标题中有这段代码(已编辑):
template <int i> class A {};
template <> class A <1> { B<1> _b; };
template <int i> class B : public A <i> {};
template <> class B <1> : public A <1> {};
并以某种方式像这样使用它:
#include "template_A_B.h"
int main ()
{
A<1> a;
B<1> b;
return 0;
}
显然我得到了编译错误:
error: ‘B’ does not name a type
如果我添加 B 的前向声明
template <int i> class B;
我明白了
error: field ‘_b’ has incomplete type
编译时。
我还尝试向前声明 A 并切换类定义的顺序并得到:
error: declaration of ‘struct A<1>’