提问人:ashura 提问时间:5/9/2023 最后编辑:cigienashura 更新时间:5/9/2023 访问量:42
为什么不能自动推导模板派生类中的父别名?[复制]
Why using parent alias from a template derived class can't be deduced automatically? [duplicate]
问:
在 C++17 中,考虑一个具有别名的基模板类,以获取封闭类型的矢量化类型:
template<typename T>
struct Foo {
using VectorType = vector<T>;
};
在非模板派生类中,我们可以简单地使用:VectorType
struct Bar : public Foo<int> {
VectorType Get(VectorType t) { return t; }
};
现在,如果我们想在模板派生类中使用它,我们需要使用:using typename
template<typename T>
struct BarT : public Foo<T> {
using typename Foo<T>::VectorType;
VectorType Get(VectorType t) { return t; }
};
从我最初的想法来看,它应该可以被编译器自动推导出来,不是吗?
有没有更好的方法,这样我就不必为派生类中的多个别名重新键入它?
答: 暂无答案
评论
typename