【发布时间】:2020-04-30 02:40:25
【问题描述】:
template<typename T>
struct A
{
using U = int;
};
struct B : A<int>
{
void f(U) // ok
{}
};
template<typename T>
struct C : A<int>
{
void f(U) // ok
{}
};
template<typename T>
struct D : A<T>
{
void f(U) // fatal error: unknown type name 'U'
{}
};
int main()
{
B b; // ok
C<int> c; // ok
D<int> d; // error
}
为什么类不能继承其父类的成员类型?
【问题讨论】:
-
我重新打开了这个问题,因为如果读者不知道为什么首先需要限定名称,“你需要使用
typename”并不能回答这个问题。
标签: c++ oop templates inheritance standards