I have this code:
#include <stdio.h>
class A
{
public:
A() { printf("A::A()\n"); }
A(const A &a) { printf("A::A(A &a)\n"); }
A &operator=(const A &a) { printf("A::operator=\n"); }
};
class B : public A
{
public:
B() { printf("B:B()\n"); }
B(const A &a) : A(a) { printf("B::B(A &a)\n"); }
B &operator=(const B &b) { printf("B::operator=\n"); }
};
int
main(int argc, char *argv[])
{
printf(">> B b1\n");
B b1;
printf(">> b2 = b1\n");
B b2 = b1;
return 0;
}
Why the line B b2 = b1
does not call the constructor B::B(const A &a)
and instead calls A::A(const A &a)
? How can I tell the compiler to do so?