这段代码因为继承了一个不完整的类型而无法编译通过(https://godbolt.org/z/G35wj9):
template<typename>
class Incomplete;
class T : public Incomplete<T> {};
template<typename>
class Incomplete {};
int main()
{
[[maybe_unused]] T x;
}
我认为这个规则同样适用于类模板。然而,这段代码可以编译通过(https://godbolt.org/z/cU6GNt):
template<typename>
class Incomplete;
template<int d>
class T : public Incomplete<T<d>> {};
template<typename>
class Incomplete {};
int main()
{
[[maybe_unused]] T<1> x;
}
当涉及到类模板时,基类只需要在实例化的时候完成吗?