将模板化基类转换运算符引入派生作用域 [英] Bring templated base class conversion operator into derived scope
问题描述
我有一个基类,它定义了一个受约束的模板化转换运算符
I have a base class that defines a constrained templated conversion operator
struct base {
template <typename C, std::enable_if_t<some_constraints<C>, int> = 0>
operator C() const;
};
我还有一个派生类,它实现了另一个具有不同约束的转换运算符:
I also have a derived class that implements another conversion operator with different constraints:
struct derived : base {
template <typename P, std::enable_if_t<different_constraints<P>, int> = 0>
operator P() const;
};
不幸的是,派生类中的声明隐藏了基类中的运算符.我想将基本运算符带入派生范围,但明显"语法
Unfortunately, the declaration in the derived class hides the operator in the base class. I would like to bring the base operator into the derived scope, but the "obvious" syntax
template <typename C>
using base::operator C;
不起作用(编译器似乎试图将其解析为别名模板声明).
doesn't work (the compiler seems to try to parse it as an alias template declaration).
有谁知道实现此目的的正确语法吗?
Does anyone know of the correct syntax to achieve this?
推荐答案
我会说这是不可能的.即使是这样,根据 namespace.udecl#15.sentence-1:
I would say it is not possible. and even if it was, your derived operator would hide base one as template argument is not part according to namespace.udecl#15.sentence-1:
当使用声明器将基类的声明引入派生类时,派生类中的成员函数和成员函数模板将覆盖和/或隐藏同名的成员函数和成员函数模板,参数类型列表基类中的 、cv 限定符和 ref 限定符(如果有)(而不是冲突)
When a using-declarator brings declarations from a base class into a derived class, member functions and member function templates in the derived class override and/or hide member functions and member function templates with the same name, parameter-type-list, cv-qualification, and ref-qualifier (if any) in a base class (rather than conflicting)
不幸的是,模板参数不计算在内,转换 operator
的参数类型列表为空,const
没有引用限定符.
Unfortunately, template parameter doesn't count and both conversion operator
has empty parameter-type-list, are const
and no ref-qualifier.
这篇关于将模板化基类转换运算符引入派生作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!