C++ 0x与使用声明混淆

Joh*_*itb 15 c++ using-declaration overload-resolution c++11

这种情况会发生什么:

struct A {
  void f();
};

struct B : virtual A {
  using A::f;
};

struct C : virtual A {
  using A::f;
};

struct D : B, C { 
  void g() {
    f();
  }
};
Run Code Online (Sandbox Code Playgroud)

感兴趣的是 f().显然,f根据10.2FDIS 的查找成功并找到A::f.但是,哪些候选人会考虑重载决议?规范说13.3.1p4:

对于由using声明引入到派生类中的非转换函数,该函数被认为是派生类的成员,用于定义隐式对象参数的类型.

这样做的目的是使单个类,如果这样一类同时包含自己的成员函数和using声明带来的基类函数的名称为范围,即重载解析过程中的所有功能,考生在他们的隐含对象是相同类型参数.但这对于上面的例子意味着什么呢?候选人是否会如下?

void F1(B&)
void F2(C&)
// call arguments: (lvalue D)
Run Code Online (Sandbox Code Playgroud)

这似乎是错误的,因为根据我们在查找结果集中只有一个声明10.2p7.我们该如何解读?

Xeo*_*Xeo 0

只是猜测,完全不确定。:)

\n\n
[ Example:\nstruct A { int x; }; // S(x,A) = { { A::x }, { A } }\nstruct B { float x; }; // S(x,B) = { { B::x }, { B } }\nstruct C: public A, public B { }; // S(x,C) = { invalid, { A in C, B in C } }\nstruct D: public virtual C { }; // S(x,D) = S(x,C)\nstruct E: public virtual C { char x; }; // S(x,E) = { { E::x }, { E } }\nstruct F: public D, public E { }; // S(x,F) = S(x,E)\nint main() {\nF f;\nf.x = 0; // OK, lookup finds E::x\n}\nS(x, F) is unambiguous because the A and B base subobjects of D are also base subobjects of E, so S(x,D)\nis discarded in the first merge step. \xe2\x80\x94end example ]\n
Run Code Online (Sandbox Code Playgroud)\n\n

是来自 10.2p7 的示例,其中S(f,C)表示查找集。最后提供的句子至关重要:Since BothDEhas the same Cbase class, and E::x hides the xfrom that C,使得最终使用F::x明确。
\n现在,在您的示例中,没有任何内容隐藏f的 基类D,因此 的使用D::f仍然不明确,我看不出 10.2p7 如何适用于您的情况。就像楼上说的,完全不确定。;)

\n