这就是我,当我在你的代码
class B : virtual public A {
class B;
public:
B() : A() (CompoundStmt 0xb85950 <a.cpp:9:5, line:11:5>)
B(A const &a) : A() (CompoundStmt 0xb859c0 <a.cpp:13:5, line:15:5>)
inline B &operator=(B const &) throw();
inline void ~B() throw();
inline B(B const &) throw() : A((ImplicitCastExpr 0xb86a10 <a.cpp:5:7> 'clas
s A const' <UncheckedDerivedToBase (virtual A)> lvalue
(DeclRefExpr 0xb869ec <col:7> 'class B const' ParmVar='' 0xb86170))
) (CompoundStmt 0xb86ab0 <a.cpp:5:7>)
试图clang++ -cc1 -ast-dump
正如你可以看到你的B
类有一个隐式声明(编译器合成的)复制构造函数。
inline B(B const &) throw():
这是C
类型的更好匹配,James McNellis表示his answer。这就是为什么你没有看到B(const A& a)
的呼叫,因为它从来没有被实际调用。
这与使用虚拟继承的事实没有任何关系;非虚拟继承会表现出相同的行为。 – 2010-09-21 15:23:09