【发布时间】:2020-08-19 16:02:48
【问题描述】:
template<typename>
struct A
{
int n;
A(bool)
{}
};
template<typename>
struct B
{
struct C : A<B>
{
using Base = A<B>;
using A<B>::A; // ok
using Base::n; // ok
// error: dependent using declaration resolved to type without 'typename'
using Base::A;
};
C get() const
{
return C(true);
}
};
int main()
{
auto b = B<int>();
b.get();
}
代码中描述了错误。
为什么不能使用 typedef 类型来声明其父类的 ctor?
【问题讨论】:
-
注意:适用于 GCC 9.3 和 MSVC v19.24。在 Clang 10.0.0 中失败(添加
typename关键字可以解决该问题,但 Clang 有 GCC 没有的其他问题)。
标签: c++ inheritance typedef using-directives using-declaration