I have the code below:
class A
{
};
class B: public virtual A
{
public:
B()
{
cerr << "B()";
}
B(const A& a)
{
cerr << "B(const A&)";
}
};
class C: public B
{
};
int main(int argc, char **argv)
{
B *b = new B(C());
}
To my surprise B(const A& a) isn’t called. Why is that?
Balso has an implicitly declared copy constructor that is declared asThis implicitly declared member function is called because it is a better match for the argument of type
Cthan your user-declared constructor,B(const A&).