【发布时间】:2020-10-14 14:03:48
【问题描述】:
考虑以下代码:
template <class R, class... Args>
using function_type = R(*)(Args...);
struct base {
template <class R, class... Args>
constexpr operator function_type<R, Args...>() const noexcept {
return nullptr;
}
};
struct derived: private base {
template <class R, class... Args>
using base::operator function_type<R, Args...>; // ERROR
};
在 C++20 中是否有可行的替代方法来继承和公开模板化转换函数?
【问题讨论】:
-
Afaics 当前的 C++2a 标准草案仍然包含阻止使用 using-declarations 引用基类的成员模板转换函数的特化的段落; eel.is/c++draft/namespace.udecl#4.sentence-2.
-
derived中是否有 其他 转换函数会隐藏base中的转换函数模板? -
@DavisHerring 它正在尝试更改访问权限。
-
@T.C.:是的——我错过了私有继承。
标签: c++ inheritance template-meta-programming c++20 conversion-operator