在繁重的模板元编程上下文中考虑基础模板类和派生模板类(此处为便于阅读并着重于此问题而对其进行了简化)。
template <class T>
struct base {
using type = T;
static constexpr int value = 0;
template <class... Args>
constexpr void function(Args&&...) {}
template <class U>
using alias_template = base<U>;
template <class U>
static constexpr int variable_template = 0;
};
template <class T>
struct derived: base<T> {
using typename base<T>::type; // Using base typedef
using base<T>::value; // Using base static data member
using base<T>::function; // Using base function members (regardless of template or not)
//using typename base<T>::alias_template; // DOES NOT SEEM TO WORK
//using base<T>::variable_template; // DOES NOT SEEM TO WORK
using typedef_test = type; // Working
static constexpr int value_test = value; // Working
using alias_template_test = alias_template<T>; // ERROR
static constexpr int variable_template_test = variable_template<T>; // ERROR
};
QUESTION: Is there a using
syntax to expose alias templates and variables templates inherited from a base class in order to make the currently erroneous lines compile? Is there any workaround to avoid to specify base<T>::
every single time in the derived class (here it remains simple, but in my actual code, specifying everytime rapidly becomes annoying)?
using
doesn't work this way for dependent member templates:我不确定这是否满足您的要求,但是为了使别名像模板一样工作,您可以在根据基本成员模板定义的派生类中声明新的成员模板: