【发布时间】:2018-03-01 02:49:27
【问题描述】:
考虑以下具有多个继承层的示例:
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,然后在A 中找到工作重载?换句话说,继承在重载解析中是否起任何作用(对于没有相同签名的函数)?
【问题讨论】:
-
不鼓励以使现有答案不正确的方式编辑问题。
-
重载根据定义有不同的签名。
标签: c++ inheritance standards c++17 overload-resolution