- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
考虑以下具有多层继承的示例:
struct A {
void operator()(double x);
};
struct B: A {
using A::operator();
template <class... T> void operator()(T... x);
};
struct C: B {
using B::operator();
void operator()() const;
void operator()(int x) const;
};
struct D: C {
using C::operator();
void operator()();
};
重载决议是否会像 D
被写成这样一样工作:
struct D {
void operator()(double x);
template <class... T> void operator()(T... x);
void operator()() const;
void operator()(int x) const;
void operator()();
};
或者相反,编译器尝试在 D
中找到工作重载,然后在 C
中,然后在 B
中,然后在一个
?换句话说,继承在重载决策(对于不具有相同签名的函数)中是否起作用?
最佳答案
一般规则是重载决策将考虑通过名称查找找到的声明集,而不是其他。
根据 [namespace.udecl]/1:
Each using-declarator in a using-declaration introduces a set of declarations into the declarative region in which the using-declaration appears. The set of declarations introduced by the using-declarator is found by performing qualified name lookup (6.4.3, 13.2) for the name in the usingdeclarator, excluding functions that are hidden as described below.
因此,在 D
范围内查找 operator()
的名称,它找到了 D::operator()
以及using-declaration,必须在 C
的范围内递归查找 operator()
,找到两个 C::operator ()
以及 using-declaration 等等。所以,是的,在您的情况下,重载解析会将整套 operator()
视为候选者。
关于c++ - 在几层继承上重载解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49041864/
我是一名优秀的程序员,十分优秀!