【发布时间】:2016-08-03 07:49:46
【问题描述】:
这是我能想到的一个小例子:
template <typename T>
struct Util
{
using Type = int;
};
struct A
{
struct B : public Util<B> {
void fun(Type) {}
};
};
template <typename T>
struct C
{
struct D : public Util<D> {
void fun(Type) {}
};
};
int main()
{
A::B{}.fun(0);
C<int>::D{}.fun(0);
}
A::B 和 C::D 之间的唯一区别是 C 是一个模板。
Struct C::D 编译失败,出现以下错误:
test_cpp.cpp:18:18: error: ‘Type’ has not been declared
void fun(Type) {}
^~~~
为什么编译失败?如何编译?
假设 Util 来自外部库,我无法更改它(如果你有兴趣,它是 boost::iterator_facade)。
【问题讨论】: