【发布时间】:2020-05-13 13:28:49
【问题描述】:
以下代码:
#include <iostream>
struct A {
using A_int = int; // A_int type declared here
virtual void foo(A_int) = 0;
};
template <typename T>
struct B : public A {
};
template <typename T>
struct C : public B<T> {
void foo(A_int) override {
std::cout << "all good\n";
}
};
int main()
{
C<int> c;
c.foo(1);
}
产生这个错误:
15:14: error: 'A_int' has not been declared
不使用模板的相同代码编译得很好。谁能解释一下为什么?
【问题讨论】:
标签: c++ templates inheritance